【以太坊】本地搭建Ethereum私有网络

一、准备创世区块配置文件

以太坊支持自定义创世区块,要运行私有链,我们就需要定义自己的创世区块,创世区块信息写在一个json格式的配置文件中。首先将下面的内容保存到一个json文件中,例如genesis.json。

{ "config": { "chainId": 15, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "difficulty": "200000000", "gasLimit": "2100000", "alloc": { "7df9a875a174b3bc565e6424a0050ebc1b2d1d82": { "balance": "300000" }, "f41c74c9ae680c1aa78f42e5647a62f353b7bdde": { "balance": "400000" } } }

二、初始化:写入创世区块

准备好创世区块配置文件后,需要初始化区块链,将上面的创世区块信息写入到区块链中。首先要新建一个目录用来存放区块链数据,假设新建的数据目录为~/privatechain/data0,genesis.json保存在~/privatechain中,此时目录结构应该是这样的:

启动节点

xiaoyu@xiaoyu-VirtualBox:~/eth$ geth --datadir "/home/xiaoyu/eth" --nodiscover --rpcapi "db,eth,net,web3" --networkid 1999 console 2>>geth.log Welcome to the Geth JavaScript console! instance: Geth/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

猜你喜欢

转载自blog.csdn.net/bjzhaoxiao/article/details/81185635