以太坊私有链部署及相关操作
私有链创建
搭建本地局域网:
1 | /bootdir$ sudo bootnode --nodekey boot.key |
部署boot1:
1 | /boot1$ sudo geth --datadir ./ --port 30321 --networkid 666 --rpc --rpcaddr 0.0.0.0 --rpcapi net,web3,eth,personal --rpcport 8110 --bootnodes "enode://ebc35b6647c7c089686382e76fdc87346417ba66f8415e13c5ecd764cab68d57f5fadb40415758265c3e315f4ff5a2714fb42246e7cc7c365dd3e32f11963198@127.0.0.1:0?discport=30301" --unlock "0xF900C29151d9cCa8D2E21882d7B99A7114De21Be" --allow-insecure-unlock --syncmode "full" console |
部署boot2:
1 | /boot2$ sudo geth --datadir ./ --port 30322 --networkid 666 --rpc --rpcaddr 0.0.0.0 --rpcapi net,web3,eth,personal --rpcport 8111 --bootnodes "enode://ebc35b6647c7c089686382e76fdc87346417ba66f8415e13c5ecd764cab68d57f5fadb40415758265c3e315f4ff5a2714fb42246e7cc7c365dd3e32f11963198@127.0.0.1:0?discport=30301" --unlock "0x0f82E6Bef49656796C4dFfdb0736a4EB3c2952B8" --allow-insecure-unlock --syncmode "full" console |
账户操作
账户查询:
1 | > eth.accounts |
此账户余额无穷,负责给本节点的其他账户转账
创建账户:
1 | > personal.newAccount("123456") |
查询账户余额:
1 | > eth.getBalance( "0x8d8350043d1c92481a109e38f7dcaf60c5a20344") |
私有链挖矿
boot1启动挖矿:
1 | > miner.start(1) //不加数字默认8个线程 |
此时会提醒”INFO [10-12|06:25:25.002] Signed recently, must wait for others”,需要在boot2中同时挖矿
结束挖矿:
1 | > miner.stop() |
查询总区块数:
1 | > eth.blockNumber |
转账交易
转账1:boot1内交易
boot1终端
1 | > n1user1 = eth.accounts[0] |
此时需要开启挖矿,通过矿工将交易写入区块中:
1 | > miner.start() |
然后终止:
1 | > miner.stop() |
重新查询账户2中的余额
1 | > eth.getBalance(n1ues2) |
转账2:boot1向boot2转账
boot2终端
1 | > personal.newAccount("654321") |
boot1终端
1 | > eth.sendTransaction({from:"0x8d8350043d1c92481a109e38f7dcaf60c5a20344",to:"0x2e55bac981f933ade1ee44943bcbb496df81d80f",value:web3.toWei(3,'ether')}) |
查询交易
转账1查询:
1 | > eth.getTransaction("0xc2046d7119b05aaacbc93ebaf47f6d7440723980a4b9aa52f87144babf8311c9") |
节点连接
1 | > net.peerCount |