美文网首页
以太坊搭建私有网络

以太坊搭建私有网络

作者: 遇见你_17be | 来源:发表于2018-11-26 17:59 被阅读0次

    https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu

    搭建私有网络

    安装软件

    sudo apt-get install software-properties-common

    sudo add-apt-repository -y ppa:ethereum/ethereum

    sudo apt-get update

    sudo apt-get install ethereum

    创建目录

    sudo mkdir tmpPrivate

    创建genesis.json

    cd tmpPrivate

    sudo touch genesis.json

    genesis.json

    {

      "config": {

            "chainId": 10,

            "homesteadBlock": 0,

            "eip155Block": 0,

            "eip158Block": 0

        },

      "alloc"      : {},

      "coinbase"  : "0x0000000000000000000000000000000000000000",

      "difficulty" : "0x02000000",

      "extraData"  : "",

      "gasLimit"  : "0x2fefd8",

      "nonce"      : "0x0000000000000042",

      "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",

      "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",

      "timestamp"  : "0x00"

    }

    初始化

    sudo geth --datadir "./" init genesis.json

    常遇到的几个错误:

    Fatal: invalid genesis file: missing 0x prefix for hex data:这个错误信息意思很明白,就是你的json文件中,对于16进制数据,需要加上0x前缀

    Fatal: invalid genesis file: hex string has odd length: 从v1.6开始,设置的十六进制数值,不能是奇数位, 比如不能是0x0,而应该是0x00。

    Fatal: failed to write genesis block: genesis has no chain configuration :这个错误信息,就是说,你的json文件中,缺少config部分。看到这个信息,我们不需要把geth退回到v1.5版本,而是需要加上config部分。

    Error: invalid sender undefined: 这个错误不会导致初始化失败,但是会在以后的转账(eth.sendTransaction),或者部署智能合约的时候产生。解决方法就是chainId 不能设置为0。 如果你完全按照github上给的官方配置文件,就会产生这个错误。

    输出日志

    geth --datadir "./" --nodiscover console 2>>geth.log

    tail -f geth.log

    sudo geth --datadir "./" --nodiscover console

    > eth.blockNumber

    0

    > personal.newAccount("yejn00001")

    "0x8806fd95b47547d64d8548fc3a42adf1bd29f730"

    > eth.coinbase

    INFO [11-26|04:16:44.036] Etherbase automatically configured      address=0x8806FD95b47547d64D8548fc3a42Adf1bd29F730

    "0x8806fd95b47547d64d8548fc3a42adf1bd29f730"

    开始挖矿:

    miner.start(1)

    以太坊私有链Geth控制台操作教程

    https://www.jianshu.com/p/9fa31e4cdf4d

    相关文章

      网友评论

          本文标题:以太坊搭建私有网络

          本文链接:https://www.haomeiwen.com/subject/avdmhftx.html