记录下搭建以太坊私有链的步骤

猿哥的环境是 Linux,实际操作时,需要替换路径、钱包地址等。

1. 到  https://geth.ethereum.org/downloads/ 下载编译好的 geth

2. 创建 genesis.json,内容如下:
{
  "config": {
        "chainId": 2206,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc"      : {},
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

注意事项: 

  • 上述内容修改了https://github.com/ethereum/go-ethereum 中的的chainId和nonce, 不修改chainId的话,可能在交易时会出现错误“ Error: insufficient funds for gas * price + value ”。
  • 猿哥原先的 gasLimit 是  0x2fefd8,但使用 truffle 发布合约到私有链的时候出现了“Error encountered, bailing. Network state unknown. Review successful transactions manually. Error: exceeds block gas limit” 这样的错误。后来修改genesis.json 中的 gasLimit 为 “0xffffffff” ,删除区块文件并重新开始挖矿,之后可以正常发布合约到私有链了。

3. 生成创世区块:

/data/eth/geth1.8.6/geth --datadir "/data/eth/database"    init /data/eth/database/genesis.json

4. 创建账户,使用其它工具如 MyEtherWalletMetaMask 创建新帐号,获得钱包地址和私钥。

5. 启动节点

nohup /data/eth/geth1.8.6/geth --gcmode archive --networkid 2006 --mine --minerthreads=1 --etherbase=你的挖矿收益钱包地址 --rpcapi admin,eth,web3,personal --verbosity 0 --rpc --rpcport 8545  --nodiscover --datadir "/data/eth/database" &

上述命令中 --nodiscover 表示不链接其它节点;--gcmode archive 表示即时将内存中的数据写入到文件中,否则重启节点可能会导致区块高度归零而丢失数据。


6. 通过私钥导导入帐号到本地

/data/geth1.8.6/geth --datadir "/data/eth/database" account import ./key.txt

key.txt 的内容只有一行,就是钱包的私钥。

猜你喜欢

转载自blog.csdn.net/weixin_42208011/article/details/80313247
今日推荐