go-ethereum搭建私有链

Environment:

  • Ubuntu 16.04
  • geth version 1.8.11

1. 初始化一个创世区块

  • 新建genesis.json配置文件,内容如下:
{
  "config": {
        "chainId": 0,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc"      : {},
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}
  • 使用下述命令,生成创世区块和初始状态
geth init genesis.json
  • 出现下图代表初始化成功

这里写图片描述

  • 可能遇到的问题

在网上发现很多人使用 geth –datadir “./geth/node” init genesis.json 指令进行初始化,加了–datadir的参数,这个参数时指定了一个空的文件夹,但是本人用这条指令测试时报如下错误
这里写图片描述
新手第一次练习,暂时没搞太懂这个参数的含义,先记录这里以后补充解释原因~~~

2 .启用私有链

使用如下命令启用私有链:

geth --identity "TestNode" --rpc --rpcport "8545" --port "30303" --nodiscover console

启动成功如下图所示:
这里写图片描述

后面的命令,都会在这个geth javascript console中执行~~~

猜你喜欢

转载自blog.csdn.net/weixin_39354676/article/details/80888186