在做一些测试工作的时候,
为了方便控制以及更快的进去真正的测试工作,大概须要搭建三个私家的以太坊互联网.

而以太坊节点之间能够彼此链接要求满意1)相同的情商版本2)相同的networkid,所以搭建私有网络最利于的方法就是因此geth命令中的–networkid选项,设置贰个与主网不一致的networkid(主网的networkid为1),那也是合法推荐的方法.

上边开头建立民用以太坊网络:

mkdir private-geth
cd private-geth

树立创世纪区块文件,是三个json格式的公文:

vim genesis.json

在创世纪区块的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": { }
}

起头化创世纪节点,并安装data目录:

geth --datadir ./data/00 init genesis.json

图片 1

起首节点,
加上console 表示运转后,启用命令行:

geth --datadir ./data/00 --networkid 15 console

 图片 2

 

今天个人互连网就搭建成功,上面就足以在这些刚刚搭建出来的个人以太坊网络中履行挖矿操作了,

挖矿首先必须有二个账户,输入下边的一声令下,查看当前node中的全数账户:

 

> eth.accounts
[]
###输出了一个"[]",说明毛都么有一根,更别说账户了.既然没有,那就来创建一个,继续输入命令:
> personal.newAccount("123456")
###正常情况,命令行会输出:
INFO [05-15|23:59:29] New wallet appeared                      url=keystore:///home/zl/Documents/p… status=Locked
"0x5b901c2495c077f515ae84fc53206f2eb3bf8296"
###再用之前查看账户的命令看看:
> eth.accounts
["0x5b901c2495c077f515ae84fc53206f2eb3bf8296"]
###有输出了"0x5b.......96"这一串就是账户的地址.
###账户有了,接下来做点更有意思的事,开始挖矿....继续在命令行书输出:
> miner.start()
INFO [05-16|00:07:25] Updated mining threads                   threads=0
INFO [05-16|00:07:25] Starting mining operation 
null
INFO [05-16|00:07:25] Commit new mining work                   number=1 txs=0 uncles=0 elapsed=38.053ms
INFO [05-16|00:07:28] Generating DAG in progress               epoch=0 percentage=0 elapsed=1.715
INFO [05-16|00:07:30] Generating DAG in progress               epoch=0 percentage=1 elapsed=3.448s
INFO [05-16|00:07:31] Generating DAG in progress               epoch=0 percentage=2 elapsed=5.059s
INFO [05-16|00:07:33] Generating DAG in progress               epoch=0 percentage=3 elapsed=6.799s
INFO [05-16|00:07:35] Generating DAG in progress               epoch=0 percentage=4 elapsed=8.373s
...................................这个percenage=100,也就是100%以后.,就不断的出现下面的提示.............
INFO [05-16|00:24:54] Successfully sealed new block            number=36 hash=95fdfd…1411ee
INFO [05-16|00:24:54] 🔗 block reached canonical chain          number=31 hash=438022…f6592e
.................................好多这个提示,挖到好多矿................................
INFO [05-16|00:24:54] 🔨 mined potential block                  number=36 hash=95fdfd…1411ee
INFO [05-16|00:24:54] Commit new mining work                   number=37 txs=0 uncles=0 elapsed=122.202µs
###然后停止挖矿:
>miner.stop(
true
###然后再来看看我们账户钱包有多少矿了:
> eth.getBalance(eth.accounts[0])
355000000000000000000

下一篇,笔者会讲一讲什么样搭建 私有互联网节点群:

Setting up private network or local cluster

参考文书档案:

http://ethdocs.org/en/latest/network/test-networks.html?highlight=private%20chain

https://github.com/ethereum/go-ethereum/wiki/Private-network

https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster

http://chainskills.com/2017/03/10/part-3-setup-the-private-chain-miners/

相关文章

网站地图xml地图