在执行完添加监视器后,执行admin.peers即可看到节点已经互联起来。
admin.peers [{ caps: ["eth/62", "eth/63"], id: "6ab4f74058b9c1e43d2d0c6f55f538ea7f2f366dd9f8f560024f14603333f017d3404b9c9711538289fa76504fecf33cf0e36cce7b0414604f673abe93012413", name: "Geth/v1.7.4-stable-a487fc95/linux-amd64/go1.9.7", network: { localAddress: "172.20.0.2:60018", remoteAddress: "172.20.0.3:30303" }, protocols: { eth: { difficulty: 131189, head: "0xa00badd4041033da53c0a34cce5aa59885d7f638e00e1e307b04c02ee640df19", version: 63 } } }, { caps: ["eth/62", "eth/63"], id: "e82fecab04e5e902a9e4ea491527ea958d2cdeb83383dfa36562e32a51eedb204a541e00ef0b497704ec0e91017799a73283e53f6dffdeef492a4230626b10b6", name: "Geth/v1.7.4-stable-a487fc95/linux-amd64/go1.9.7", network: { localAddress: "172.20.0.2:36700", remoteAddress: "172.20.0.4:30303" }, protocols: { eth: { difficulty: 131076, head: "0xe30ff3a8d1ae16384369c45d106841ef44e83c12eae2e2c66dce1bdccc9ba4d6", version: 63 } } }]注意:这一步完成了,仅仅是临时的,每次重启docker之后admin.peers会重新为空。
9. 配置永久互联临时互联不方便,可以将bootnodes配置到启动文件中。
修改docker-compose.yml文件,将节点1的连接配置进去。
这个时候,“主网”启动成功了!!!
五、运行 1. 解锁账户分别在3个节点上把validator无限期解锁,谁不解锁谁别出块、跳过你。
这里源码默认10秒1块。
进入geth JavaScript控制台后,执行以下命令:
根据美图解释,这里validator和coinbase的区别:
coinbase:收取挖矿奖励
validator:可以设置为其他地址,但默认和coinbase一样。
2. 启动挖矿进入geth JavaScript控制台后,执行以下命令:
miner.start() 3. 获取区块信息进入geth JavaScript控制台后,执行以下命令:
# 模板 eth.getBlock(区块编号) # 例子 eth.getBlock(1) # 结果 { coinbase: "0x849f9442198282fb21539351edb0378463e4c251", difficulty: 1, extraData: "0xd783010704846765746887676f312e392e37856c696e7578000000000000000084c3b20f15eb99c19bb8567d3a27a52947efb816f647cbc4491540ee5de685d54f4126d236f031d33312dfab1a5d7a895bbd4d154afd366b30918a9af6868ab300", gasLimit: 5237761, gasUsed: 0, hash: "0x30964585add8b4ef65529f38ebe00bb6581fc9ae7323327f7dfd666754de883b", logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000", nonce: "0x0000000000000000", number: 1, parentHash: "0x9390ffeae9812417704193667a0e106c8cd9e701217deb054737dab0325191d3", receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", size: 794, stateRoot: "0xc5a87ecb7262f6c507f488f5f93efa27df81550f1e7691c1ab2093a4218d2ca0", timestamp: 1543990290, totalDifficulty: 131073, transactions: [], transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", uncles: [], validator: "0x849f9442198282fb21539351edb0378463e4c251" } 六、测试 1. 获取账户余额 # 获取账户 eth.accounts # 获取余额 eth.getBalance(账户地址) # 格式化长度 web3.fromWei(数值) # 获取格式化后的余额,默认取第一个账户 web3.fromWei(eth.getBalacne(eth.accounts[0])) # 获取指定账户余额 web3.fromWei(eth.getBalance("0x849f9442198282fb21539351edb0378463e4c251")) 2. 交易 # 模板 eth.sendTransaction({from: "发送者", to: "接受者", value: 数量}) # 例子 eth.sendTransaction({from: "0x849f9442198282fb21539351edb0378463e4c251", to: "0xc4118320f3d3c37a2ca8dad5c2f2a40f2a23ba02", value: 1000000000000000000})