使用go-ethereum建立私鏈

ref:

http://blog.csdn.net/lhtzbj12/article/details/79405238

https://www.cnblogs.com/jackluo/p/8513880.html



>docker pull ethereum/client-go

>cd docker_ethereum/
>[root@mo-cn-491 docker_ethereum]# ls
data  start_ethereum.sh



start-ethereum.sh的內容如下

複製代碼
docker stop ethereum-node
docker rm ethereum-node

docker run -d --name ethereum-node -v /home/[email protected]/hrs_doc/docker_ethereum/data:/root \
           -p 8545:8545 -p 30303:30303 \
           ethereum/client-go
docker exec -it ethereum-node /bin/sh

複製代碼

我們根據官方的文檔 創建 genesis.json文件裏面寫入

複製代碼
{
  "config": {
        "chainId": 12,  //這裏不能爲0,否則轉賬時報錯
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc"      : {},
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}
複製代碼
>./start-ethereum.sh
/ # cd /root/
~ # ls
genesis.json 
#geth --datadir data0 init genesis.json
#ls
data0         genesis.json
#geth  --networkid 12 --identity "TestNode" --rpc --rpcport "8545" --datadir data0 --port "3033" --nodiscover console
>eth.accounts
>personal.newAccount('123456')
>personal.newAccount('123456')
> personal.unlockAccount(eth.coinbase)
>us1=eth.accounts[0]
>us2=eth.accounts[1]
>eth.sendTransaction({from:us1,to:us2,value:web3.toWei(3,"ether")})
>eth.getBalance(us1)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章