使用Geth搭建多节点私有链

使用Geth搭建多节点私有链

步骤

1.编辑初始化配置文件genesis.json


{
    "config": {
      "chainId": 6668,
      "homesteadBlock": 0,
      "eip150Block": 0,
      "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "eip155Block": 0,
      "eip158Block": 0,
      "byzantiumBlock": 0,
      "constantinopleBlock": 0,
      "petersburgBlock": 0,
      "istanbulBlock": 0,
      "ethash": {}
    },
    "nonce": "0x0",
    "timestamp": "0x5ddf8f3e",
    "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "gasLimit": "0x47b760",
    "difficulty": "20000",
    "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x0000000000000000000000000000000000000000",
    "alloc": { 
        
    },
    "number": "0x0",
    "gasUsed": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
  }

2.启动节点1

geth --datadir chainA init genesis.json

使用Geth搭建多节点私有链_第1张图片

geth --datadir chainA --networkid 123 console --nodiscover

使用Geth搭建多节点私有链_第2张图片

3.另开一个终端,启动节点2

geth --datadir chainB init genesis.json

使用Geth搭建多节点私有链_第3张图片

geth --datadir chainB --networkid 123 --port 30302 --http --http.port 8552 --http.addr 127.0.0.2 --ipcdisable console --nodiscover --authrpc.addr 127.0.0.2

使用Geth搭建多节点私有链_第4张图片

4.节点连接

4.1 获取节点1的encode并复制 admin.nodeInfo.enode

在这里插入图片描述

4.2 节点2连接节点1 admin.addPeer("")

在这里插入图片描述

4.3 在节点2获取节点1信息 admin.peers

使用Geth搭建多节点私有链_第5张图片

常见错误

1.套接字地址只允许使用一次,节点1开启已占用。加上--authrpc.addr 127.0.0.2

Fatal: Error starting protocol stack: listen tcp 127.0.0.1:8551: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

2.因为版本问题,–rpc已不使用

Incorrect Usage. flag provided but not defined: -rpc

  • –rpc => --http
  • –rpcapi => --http.api
  • –rpcaddr => --http.addr
  • –rpcport => --http.port
  • –rpccorsdomain => --http.corsdomain

你可能感兴趣的:(以太坊,rpc,web3)