区块链:以太坊基础之搭建私链

心不动则不痛 提交于 2020-01-07 18:58:41

1.新建genesis.json

{  "config": {    "chainId": 666,    "homesteadBlock": 0,    "eip150Block": 0,    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",    "eip155Block": 0,    "eip158Block": 0,    "byzantiumBlock": 0,    "constantinopleBlock": 0,    "petersburgBlock": 0,    "istanbulBlock": 0,    "ethash": {}  },  "nonce": "0x0",  "timestamp": "0x5ddf8f3e",  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",  "gasLimit": "0x47b760",  "difficulty": "0x00002",  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",  "coinbase": "0x0000000000000000000000000000000000000000",  "alloc": {    "0x1e82968C4624880FD1E8e818421841E6DB8D1Fa4" : {"balance" : "30000000000000000000"}  },  "number": "0x0",  "gasUsed": "0x0",  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"}

各个参数的解释可参考:https://www.cnblogs.com/wanghui-garcia/p/10256520.html

 

如果没有alloc后面的部分,可能出现:Fatal: Failed to write genesis block: unsupported fork ordering: eip150Block not enabled, but eip155Block enabled at 0 错误

具体参考:http://www.blogjava.net/waterjava/archive/2019/11/28/434937.html

2.启动

2.1.初始化

geth --datadir /usr/geth/data init /usr/geth/config/genesis.json

2.2.启动私链并进入控制台

geth --datadir /usr/geth/data --networkid 666 console

3.创建账户挖矿

3.1.创建账户

personal.newAccount()  然后根据提示输入密码

personal.newAccount("123456")  创建账户的同时指定密码

3.2.挖矿

miner.start(1)  括号里不填的话是默认全力挖矿

3.3.停止

miner.stop()  停止挖矿

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!