參考 這篇https://www.codeooze.com/blockchain/ethereum-geth-private-blockchain/ 說的已經很詳細了 html
genesis.json 過期了可參考https://mlgblockchain.com/ethereum-private-network.html
修改成以下
web
{json
"config" :{api
"chainId": 16,cors
"homesteadBlock": 0,dom
eip155Block": 0,spa
eip158Block":0.net
},code
"nonce": "0x0000000000220042",htm
"timestamp": "0x0",
parentHash": "0x000000000000000000",
"mixhash": "0x000000000000000000",
"gasLimit": "0x8000000",
"difficulty": "0x10",
"alloc":{}
}
geth --datadir privchain init genesis.json
geth --port 3000 --networkid 58342 --nodiscover --datadir="privchain" --maxpeers=0 --rpc --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3"
而後新啓動一個終端輸入 以下
geth attach ipc://home/someone/privchain/geth.ipc
geth啓動基本也就完成了
personal.newAccount('password')
personal.unlockAccount(web3.eth.coinbase, "password", 15000) 解鎖帳戶 否則發佈的時候會報錯 15000應該是時間 超時以後從新解鎖帳戶就能夠了
miner.start() 保證挖礦狀態
truffle migrate --reset (此處爲了不遇到錯誤 我直接帶上reset參數)
truffle console
HelloWorld.deployed() 就算完成了
中途遇到2個錯誤 其一 Error: No network specified. Cannot determine current network異常
緣由是 truffle配置文件中沒有指定networkid
致使上面異常的緣由爲是由於truffle.js裏面未配置連接合約發佈的環境地址,找到對應的truffle.js文件,修改代碼爲相似以下配置便可解決問題:
module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*" // 匹配任何network id } } };其二 Error: Exceeds block gas limitgas給的(或者消耗的)太多超出區塊最大的gas限制量了 修改gaslimit