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

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()  停止挖矿

上一篇:flask教程之路由


下一篇:SpringBoot+MyBatisPlus+Shiro+Layui简单权限管理系统