1. 程式人生 > >以太坊POA搭建聯盟鏈——geth命令手記

以太坊POA搭建聯盟鏈——geth命令手記

創世塊使用:puppeth建立

參考:https://blog.csdn.net/code_segment/article/details/78160660

 

密碼:123
node:
128809dd3d9fe616381ce21b868191ce90091c7e

04757dd260325fd85dfb1d8bdbf75f4f64e8f5a8


signer:
a0187bd2b4ba0235ed3327a38b45bb6ea60b3549


8a098a17c39d4cb1ce76dbabfdf02e935a558211

node1: geth --datadir ./data     --port 2001 console 
node2: geth --datadir ./data     --port 2002 console 
signer1後臺執行:  nohup geth --datadir  ./data  --mine --port 2003  --rpc --rpcaddr localhost --rpcport 8545 --rpcapi "db,eth,net,web3,admin,miner,personal,rpc,txpool"   --unlock  "a0187bd2b4ba0235ed3327a38b45bb6ea60b3549"  --password "password.txt"  &
signer1啟動: geth --datadir  ./data    --rpc --rpcaddr localhost --rpcport 8545  --unlock  "a0187bd2b4ba0235ed3327a38b45bb6ea60b3549"     --password "password.txt" 
 
signer2後臺: nohup geth --datadir ./data  --mine  --port 2004 --unlock  "8a098a17c39d4cb1ce76dbabfdf02e935a558211"     --password "password.txt"  &

signer2: geth --datadir  ./data    --port 2004 --unlock  "8a098a17c39d4cb1ce76dbabfdf02e935a558211" console 
 


創世塊:geth init ./genesis.json --datadir "./chain" 

1. geth --datadir chain --ipcpath chain/geth.ipc  --nodiscover --rpc --rpcaddr localhost --rpcport 8080 --port 3000 --rpcapi "db,eth,net,web3,admin,miner,personal,rpc,txpool" 

>>eth_output.log

2. geth attach ipc:http://localhost:8545

3.建立賬戶:web3.personal.newAccount("123456")

4.收益賬戶:eth.coinbase

5.查詢餘額:web3.fromWei(eth.getBalance(eth.coinbase), "ether")

web3.fromWei(eth.getBalance("0xa95222123d32b3515bf9f561feb6a2530522c3b9"), "ether")

6.修改挖礦收益賬戶:miner.setEtherbase("0xe6d5a0e6e02853547fabed0fb975bdac854e7d8b")
web3.fromWei(eth.getBalance("0x04757dd260325fd85dfb1d8bdbf75f4f64e8f5a8"), "ether")


7.txpool.status 
{
  pending: 0,
  queued: 0
}
8.轉賬: web3.personal.unlockAccount(web3.eth.accounts[0],"123")
1:  web3.personal.unlockAccount(web3.eth.accounts[0],"123456")
   web3.eth.sendTransaction({from:web3.eth.accounts[0],to:web3.eth.accounts[1],value:web3.toWei(3,"ether")})
 
2: web3.eth.sendTransaction({from:"0xa0187bd2b4ba0235ed3327a38b45bb6ea60b3549",to:"0xa2a191ced99c200e7932f82d98828dd8e31f5421",value:web3.toWei(100,"ether")})


9 節點地址:admin.nodeInfo.enode 
新增節點: admin.addPeer

("enode://0bab976daa9f669543c8f6192785643ada31fb6e77c5c3d885307b5dfe80001b5[email protected]0.0.0.0:3000")
admin.addPeer("enode://57a8c11428981a827d7d2344ff26355d27dca54506a29a800b6204518d1730ac7[email protected][::]:30303")

admin.addPeer("enode://12f1cec16e2838a6e5acebe38a345f634262bf065e13c49f9fd456da2b2d914da[email protected][::]:2004")
poa:
1.啟動節點
geth --datadir ./data      --port 2001 console 
 geth --datadir ./data   --ipcdisable --rpc --rpcaddr localhost --rpcport 8080 --port 3000 --rpcapi "db,eth,net,web3,admin,miner,personal,rpc,txpool" >>eth_output.log
2.啟動並且解鎖賬戶(signer簽名者)注意 交易簽名在siger1
geth --datadir  ./data  --rpc --rpcaddr localhost --rpcport 8080    --port 2003 --unlock  "a0187bd2b4ba0235ed3327a38b45bb6ea60b3549" console 
geth --datadir  ./data    --port 2004 --unlock  "8a098a17c39d4cb1ce76dbabfdf02e935a558211" console 

授權其他節點作為signer,當signer有多個時,需要大於51%完成簽名,當需要刪除某個singer時同樣需要>51%,signer可以刪除自己:
clique.propose("0x8a098a17c39d4cb1ce76dbabfdf02e935a558211",true)//新增
clique.discard("0x8a098a17c39d4cb1ce76dbabfdf02e935a558211")     /刪除