搭建以太坊私有链
1. go-ethereum客户端安装
系统环境 ubuntu16.4
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get update
sudo apt-get install ethereum
ps:通过运行geth --help 来判断是否安装成功(安装ok 后有geth 相关命令帮助文档)
2. 建立创世块
新建eth 目录在该目录下新建创世快json 文件genesis.json 如下:
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x40000",
"extraData" : "",
"gasLimit" : "0xffffffff",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc": { }
}
相关参数解释如下:
| 参数 | 描述 |
|---|---|
| mixhash | 与nonce配合用于挖矿,由上一个区块的一部分生成的hash。注意他和nonce的设置需要满足以太坊的Yellow paper, 4.3.4. Block Header Validity。 |
3. 初始化创世块
geth --datadir ./data/00 init genesis.json
4.启动私有链
geth --identity "secbro ethrum" --rpc --rpccorsdomain "*" --datadir "/home/scoft/eth/data0/" --port "30303" --rpcapi "db,eth,net,wbb3" --networkid 95518 console
5. 查看账户
eth.accounts
6. 创建账户
personal.newAccount("account1")
ps account1 为账户的密码
7. 开始挖矿
挖矿产生的奖励默认给本地节点中coinbase个帐户,默认是第一个账户也,可以通过```miner.setEtherbase()``` 将其他账户设置成coinbase
如:
miner.setEtherbase(eth.accounts[1])
miner.start()
8. 停止挖矿8.
miner.stop()
9. 发送交易
在交易前必须先解锁账号 ```personal.unlockAccount(eth.accounts[0]) ```
eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:amount})
要是交易被完成,必须要挖矿,启动挖矿后,等待挖到一个区块后停止挖矿:

浙公网安备 33010602011771号