預(yù)挖礦
如果希望在指定的賬戶中有一定的eth供測試,可以先新建一個賬戶,將這個賬戶放到創(chuàng)世區(qū)塊的配置文件中
root@iZ2ze1lsoerlt75gu9joguZ:/var/eth# ./geth --datadir private_data/ account new
WARN [09-29|12:01:31] No etherbase set and no accounts found as default
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {7babfbc6938cf9968d6b106e8618328d1478e79e}
這里要注意的是,指定私有數(shù)據(jù)目錄,后面的創(chuàng)世區(qū)塊命名也要一致
創(chuàng)世區(qū)塊配置
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "0x4000",
"gasLimit": "2100000",
"alloc": {
"7babfbc6938cf9968d6b106e8618328d1478e79e": { "balance": "10000000000000000000000" }
}
}
alloc非必須字段,如果不預(yù)挖礦,可不要,另外balance的單位是wei,1個以太幣=10^18wei,后面要加足夠的0,然后運行初始化命令
root@iZ2ze1lsoerlt75gu9joguZ:/var/eth# ./geth --datadir private_data/ init genesis.json
INFO [09-29|12:04:17] Allocated cache and file handles database=/var/eth/private_data/geth/chaindata cache=16 handles=16
INFO [09-29|12:04:17] Writing custom genesis block
INFO [09-29|12:04:17] Successfully wrote genesis state database=chaindata hash=5d1258…d0deb6
INFO [09-29|12:04:17] Allocated cache and file handles database=/var/eth/private_data/geth/lightchaindata cache=16 handles=16
INFO [09-29|12:04:17] Writing custom genesis block
INFO [09-29|12:04:17] Successfully wrote genesis state database=lightchaindata hash=5d1258…d0deb6
看到success,也就OK了,現(xiàn)在看看賬戶中余額是不是有了余額,進入console
root@iZ2ze1lsoerlt75gu9joguZ:/var/eth# ./geth --datadir private_data/ console
> web3.fromWei(eth.getBalance(eth.accounts[0]),'ether')
10000
嗯,給定賬戶中有一萬個幣了,想想是千萬富翁了。。。