79

基于以太坊的多节点私链系统搭建

 5 years ago
source link: https://studygolang.com/articles/18283?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

基于以太坊的多节点私链系统

一、环境

Golang https://golang.org/

Geth https://ethereum.github.io/go-ethereum/downloads/ (make all 编译goeth)

二、节点部署(包含接入、共识、全量记录节点)

创建账号

geth --datadir node0 account new

目录下会增加keystore文件夹,keystore是保存账户密钥的文件

创世区块文件genesis.json

genesis文件定义了私链的第一个块,可以使用puppeth工具来生成,可以自定义出块时间共识算法等

mu6R3qb.png!web

image.png

初始化

geth --datadir node0 init genesis.json(步骤2生成)

node0目录下会增加geth ,geth存储区块相关的数据

启动第一个节点

创建创世块:

geth --datadir node0 init genesis.json

启动:

geth --datadir node0 --port 30000 --nodiscover --unlock '账户地址'  console

加入新的节点

创建账号:

geth --datadir node1 account new

创建创世块:

geth --datadir node1 init genesis.json(步骤2生成的)

启动节点:

geth --datadir node1 --port 30000 --nodiscover --unlock '地址'  console

在node1控制台通过admin.nodeInfo.enode 获取enode信息

在node0控制台通过admin.addPeer("enode信息") 添加节点

当增加第三个节点时,由于超过3个,节点启动miner会报unauthorized 错误,这是因为新节点的加入需要一半以上的节点提名,控制台中执行:

clique.propose(ldquo;账户地址rdquo;,true)

开启rpc服务(接入节点和全量交易记录节点启用)

admin.startRPC("127.0.0.1",8545,"*","eth,net,web3,admin,personal")

开启挖矿(共识节点启用)

miner.start()

三、使用

nYBFJrm.png!web

image.png

客户端通过相应的SDK调用接入节点,完成合约部署,合约调用、数据查询等功能。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK