以太坊私有链搭建

前言

现在区块链很火热,各种ICO飞起,第一次听说比特币是在2015年年底,不过当时更注意的是大数据。 现在比特币已经买不起了,只能买半个eth玩玩,听说智能合约很火,决定自己搭个环境研究研究。

搭建以太坊私有链

第一个节点

1、下载并安装geth

1
2
http://upyun-assets.ethfans.org/geth/1-7-3/geth-windows-amd64-1.7.3-4bb3c89d.exe
来源 : http://ethfans.org/wikis/Ethereum-Geth-Mirror

2、进入geth安装目录,创建json配置文件 (dxwgenesis.json)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"config": {
"chainId": 0,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x4000",
"extraData" : "0x6d616f62656e636f6e67",
"gasLimit" : "0xffffffff",
"nonce" : "0x0000000000000904",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}

3、创建区块数据目录chains并初始化创世块。

1
geth --datadir "chains" init dxwgenesis.json

4、开启第一个节点,并进入控制台

1
geth.exe --datadir "chains" --networkid 321123 --ipcdisable --port 904 --rpcport 9904 console

5、查看并记录nodeinfo

1
2
3
控制台数据 admin.nodeInfo.enode
输出:
"enode://8a4b1689521ca5872c129425dff5c00800adf4ea802b93708bfd2ef935fe915e9b798b7ec14067856ae2ede1298253978a0667754b33834d75672aeb4e16ce43@223.20.146.255:904"

第二个节点

1、依次按照节点一 1-3步执行。 2、启动节点二,将bootnodes后面的数值改为节点一的nodeInfo,注意:所有节点的networkid应该一致!

1
./geth --datadir "chains_2" --networkid 321123 --ipcdisable --port 905 --rpcport 9905 --bootnodes "enode://8a4b1689521ca5872c129425dff5c00800adf4ea802b93708bfd2ef935fe915e9b798b7ec14067856ae2ede1298253978a0667754b33834d75672aeb4e16ce43@192.168.1.101:904" console

挖矿

1、所有命令在节点的console中输入

1
2
miner.start() 开始挖矿。
miner.stop() 结束挖矿。

2、查看当前节点的用户

1
Eth.accounts

源码编译

以太坊编译参考 https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu