1. 程式人生 > >創始區塊鏈初始化

創始區塊鏈初始化

	想知道更多區塊鏈技術知識,請百度【鏈客區塊鏈技術問答社群】

如果通過創世區塊來初始化區塊鏈的話,首先需要一個初始化區塊鏈的json檔案,如下。
{
“config”: {
“chainId”: 15,
“homesteadBlock”: 0,
“eip155Block”: 0,
“eip158Block”: 0
},
“difficulty”: “4”,
“gasLimit”: “2100000”,
“alloc”: {
“7df9a875a174b3bc565e6424a0050ebc1b2d1d82”: {
“balance”: “300000”
},
“f41c74c9ae680c1aa78f42e5647a62f353b7bdde”: {
“balance”: “400000”
}
}}
config, difficulty, gasLimit, alloc創始區塊檔案中,這幾個檔案是必須的。
初始化區塊鏈,並且建立一個資料夾來儲存區塊資料
geth init genesis.json --datadir private_data
開啟終端
geth --networkid 888 --datadir private_data console

檢視餘額

eth.getBalance(“7df9a875a174b3bc565e6424a0050ebc1b2d1d82”)
300000>
開始 mining
miner.start()
INFO [10-15|07:57:15] Updated mining threads threads=0
INFO [10-15|07:57:15] Transaction pool price threshold updated price=18000000000
ERROR[10-15|07:57:15] Cannot start mining without etherbase err=“etherbase address must be explicitly specified”
Error: etherbase missing: etherbase address must be explicitly specified
at web3.js:3104:20
at web3.js:6191:15
at web3.js:5004:36
at :1:1

如果你直接挖礦,會出現上面的錯誤。需要設定一個挖礦的賬號。

miner.setEtherbase(“7df9a875a174b3bc565e6424a0050ebc1b2d1d82”)true

好了,那麼接下來就可以開始挖礦了,看起來和寫起來都是相對比較簡單的,大家加油努力學習,哈哈。