zoukankan      html  css  js  c++  java
  • 以太坊geth区块链私链建立

     

    以太坊geth区块链私链建立

    geth的github https://github.com/ethereum/go-ethereum

    下载最新(1.8)的geth,windows下安装很简单

    关于私链在geth的github wiki上private network一章有指南,下面进行部分翻译和整合

    (In this context private only means reserved or isolated, rather than protected or secure.私链仅指私有,并不指安全或受保护)

    选择network id

    (此处network指私链所在的网络)

    简而言之,建议你使用networkid标识你的网络,要不然会于id=1的链(同时id=1也是default值冲突),就是公链冲突。

    建立创世区块(Genesis Block)

    wiki提供的创世区块为

    {
    "config": {
    "chainId": 15,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
    },
    "difficulty": "200000000",
    "gasLimit": "2100000",
    "alloc": {
    "7df9a875a174b3bc565e6424a0050ebc1b2d1d82": { "balance": "300000" },
    "f41c74c9ae680c1aa78f42e5647a62f353b7bdde": { "balance": "400000" }
    }
    }

    创世区块为

    {
      "config"     :{
            "chainId": 1024,
            "homesteadBlock": 0,
            "eip155Block": 0,
            "eip158Block": 0
        },
      "coinbase"   : "0x0000000000000000000000000000000000000000",
      "difficulty" : "0x20000",
      "gasLimit"   : "0xffffff",
      "nonce"      : "0x0000000000000042",
      "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
      "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
      "timestamp"  : "0x00",
      "alloc"      : {}

    }

    部分参数解释:

    alloc:提前分配账号与其中币量;

    "alloc": {
            "7df9a875a174b3bc565e6424a0050ebc1b2d1d82": { "balance": "300000" },
            "f41c74c9ae680c1aa78f42e5647a62f353b7bdde": { "balance": "400000" }
        }

    gaslimit:币最大量

    nonce:随机数,用于配合挖矿

    mixhash:参考黄皮书(我也不懂)

    difficulty:设置当前区块的难度,如果难度过大,cpu挖矿就很难,这里设置较小难度

    extraData:区块附加信息

    config:The config section ensures that certain protocol upgrades are immediately available.  没怎么看懂

    当前目录下创建chain文件夹储存创世区块

    .geth --datadir "chain" init genesis.json

    进入调控台

    .geth --datadir "chain" console

    ipconfig查询本机ip

    得到192.168.1.101

    .geth –targetgaslimit 4294967295 –rpc –rpcaddr “192.168.1.101” –rpcport “8101” –port “30301” –rpcapi “eth,web3,personal” –networkid 1024 –identity 1024 -nodiscover -maxpeers 5 –datadir “chain” -unlock 0 -rpccorsdomain “*” –mine console

    启动私有链节点 

    注释

    targetgaslimit –每个块的gas上限,这里可以暂时理解为容量 rpc –启动rpc通信,可以进行智能合约的部署和调试 rpcaddr –rpc接口的地址 rpcport –rpc接口的端口号 port –网络监听端口,用于节点之间通信 rpcapi –设置rpc的范围,暂时开启eth,web3,personal足够 networkid –设置当前区块链的网络ID,是一个数字,可以随便写 identity –区块链的标示,随便填写,用于标示目前网络的名字 nodiscover 禁止被网络中其它节点发现,需要手动添加该节点到网络 maxpeers 最大节点数量 datadir –设置当前区块链网络数据存放的位置 unlock –解锁某用户(此处用用户坐标来控制,解锁后的用户调用接口发起交易时,不要需要提供密码) rpccorsdomain 限制rpc访问源的ip,代表不限制 mine 允许挖矿 console –启动命令行模式,可以在Geth中执行命令*

    或者使用 .geth --datadir "chain" --dev.period 1 console

    http://blog.csdn.net/wo541075754/article/details/79260040


    等待 DAG 变100% 自动开始挖矿 此时可以停止挖矿

    miner.stop()

    打开Mist

    注意左下角标识private

    至此成功配置私有链

    问题:

    cannot unmarshal hex string without 0x prefix into Go struct field Genesis. extraData of type hexutil.Bytes

    貌似是value值必须以0x开头,而extraData开头不是0x,貌似只能把extradata删了,或者将你的文字转成16进制

    invalid character '}' looking for beginning of object key string

    注意最后一个元素后面( ‘}’前)别加逗号

  • 相关阅读:
    小技巧
    常用的交互设计软件
    Android studio 使用SVN需要忽略的文件
    android studio 使用SVN 锁定文件,防止别人修改(基于Android studio 1.4 )
    git 和 github 关系?
    Double 数据保留两位小数一:五舍六入
    设计模式
    Java中关于日期类那些方法
    ios 开源免费接口
    华为招聘机试整理5:简单四则运算
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/11205613.html
Copyright © 2011-2022 走看看