https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu
搭建私有網(wǎng)絡(luò)
安裝軟件
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
創(chuàng)建目錄
sudo mkdir tmpPrivate
創(chuàng)建genesis.json
cd tmpPrivate
sudo touch genesis.json
genesis.json
{
? "config": {
? ? ? ? "chainId": 10,
? ? ? ? "homesteadBlock": 0,
? ? ? ? "eip155Block": 0,
? ? ? ? "eip158Block": 0
? ? },
? "alloc"? ? ? : {},
? "coinbase"? : "0x0000000000000000000000000000000000000000",
? "difficulty" : "0x02000000",
? "extraData"? : "",
? "gasLimit"? : "0x2fefd8",
? "nonce"? ? ? : "0x0000000000000042",
? "mixhash"? ? : "0x0000000000000000000000000000000000000000000000000000000000000000",
? "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
? "timestamp"? : "0x00"
}
初始化
sudo geth --datadir "./" init genesis.json
常遇到的幾個錯誤:
Fatal: invalid genesis file: missing 0x prefix for hex data:這個錯誤信息意思很明白计螺,就是你的json文件中奉件,對于16進制數(shù)據(jù)蒿褂,需要加上0x前綴
Fatal: invalid genesis file: hex string has odd length: 從v1.6開始懈费,設(shè)置的十六進制數(shù)值侄榴,不能是奇數(shù)位, 比如不能是0x0埋虹,而應(yīng)該是0x00盼玄。
Fatal: failed to write genesis block: genesis has no chain configuration :這個錯誤信息,就是說缘薛,你的json文件中窍育,缺少config部分⊙珉剩看到這個信息漱抓,我們不需要把geth退回到v1.5版本,而是需要加上config部分恕齐。
Error: invalid sender undefined: 這個錯誤不會導(dǎo)致初始化失敗乞娄,但是會在以后的轉(zhuǎn)賬(eth.sendTransaction),或者部署智能合約的時候產(chǎn)生显歧。解決方法就是chainId 不能設(shè)置為0仪或。 如果你完全按照github上給的官方配置文件,就會產(chǎn)生這個錯誤士骤。
輸出日志
geth --datadir "./" --nodiscover console 2>>geth.log
tail -f geth.log
sudo geth --datadir "./" --nodiscover console
> eth.blockNumber
0
> personal.newAccount("yejn00001")
"0x8806fd95b47547d64d8548fc3a42adf1bd29f730"
> eth.coinbase
INFO [11-26|04:16:44.036] Etherbase automatically configured? ? ? address=0x8806FD95b47547d64D8548fc3a42Adf1bd29F730
"0x8806fd95b47547d64d8548fc3a42adf1bd29f730"
開始挖礦:
miner.start(1)
以太坊私有鏈Geth控制臺操作教程