以太坊私有链搭建(1)-基础

2017-09-29  本文已影响0人  十三流

预挖矿

如果希望在指定的账户中有一定的eth供测试,可以先新建一个账户,将这个账户放到创世区块的配置文件中

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}

这里要注意的是,指定私有数据目录,后面的创世区块命名也要一致

创世区块配置

{
    "config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "difficulty": "0x4000",
    "gasLimit": "2100000",
    "alloc": {
        "7babfbc6938cf9968d6b106e8618328d1478e79e": { "balance": "10000000000000000000000" } 
    }
}

alloc非必须字段,如果不预挖矿,可不要,另外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了,现在看看账户中余额是不是有了余额,进入console

root@iZ2ze1lsoerlt75gu9joguZ:/var/eth# ./geth  --datadir private_data/ console
> web3.fromWei(eth.getBalance(eth.accounts[0]),'ether')
10000

嗯,给定账户中有一万个币了,想想是千万富翁了。。。

上一篇下一篇

猜你喜欢

热点阅读