以太坊 POA 部署

tech2022-10-24  97

cd $GOPATH/src/github.com/ethereum 1. 下载源码 git clone https://gitee.com/xgqnytz/go-ethereum.git git checkout v1.8.27 go install github.com/ethereum/go-ethereum/cmd/geth cd go-ethereum/ make geth make all 安装后检查: geth version 2. 初始化配置 工作路径在 /work/geth mkdir -p /work/geth cd /work/geth 创建两个文件夹存放节点数数据,地址信息等 madir node1 node2 $ geth --datadir node1 account new $ geth --datadir node2 account new 这两条命令会在两个文件夹下生成两个地址 此步骤主要生成用户的keystore密钥文件,有此文件才能将账户添加进区块链 注:此命令需要输入2次账户密码,会返回账户地址以及私钥 --datadir:设置数据储存地址 account new:account:账户管理命令,new:生成新账户,会在数据目录下创建keystore目录,存放一个账 户的秘钥文件 生成genesis.json go-ethereum自带puppeth工具, 可以方便地部署支持PoA的以太坊私链 初次使用可采用下面的流程: $ puppeth 依次 让你选择 1 :自定义这个网络的名称,也是你的genesis文件的名称 2 : 选择第二个 Configure new genesis 3 : 选择第一个 Create new genesis from scratch 4 : 选择第二个 proof-of-authority (POA共识) 5 : 自定义出块的时间间隔,默认单位为s 这里测试 输入 10 6 : 配置初始参与共识的地址,也就是指定矿工,这里输入上面命令生成的两个地址,每输入一个地址回车一次,不输入时直接回车进入下一环 7 : token的发放,与上一环类似,自行配置地址接受奖励 8 : 默认回车就行,给一个预编译地址预留1 wei 9 : chain/network ID 默认回车,系统会随机生成 以上 配置完成后,选择第2条 Manage existing genesis , 然后选择导出 Export genesis configurations 导出genesis文件,可自行配置名称 以上完成后,ctr+c 终端命令 退出 默认条件下 当前目录下 生成 .json 的配置文件 3. 启动节点,在两个终端上执行,工作路径同样, node1: geth --datadir node1 init testnet.json geth --datadir node1 --port 3000 --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpccorsdomain "*" --rpcapi "db,eth,net,web3,personal,miner" --syncmode "full" console node2: geth --datadir node2 init testnet.json geth --datadir node2 --port 3001 --nodiscover --rpc --rpcaddr 0.0.0.0 --rpcport 8546 --rpccorsdomain "*" --rpcapi "db,eth,net,web3,personal,miner" --syncmode "full" console node1 node2 互相添加节点信息 两个终端分别执行下 admin.nodeInfo.enode 获取当前节点连接信息,返回的结果,用于他人跟你建立连接 admin.addPeer() 新增连接,参数为上一步的输出 常用Api: 解锁账户 地址,密码,时间 personal.unlockAccount(eth.coinbase,"123456",1000000) 配置默认账户 eth.defaultAccount = eth.coinbase 启动挖矿 miner.start() miner.stop() 有其他错误时,需先关闭挖矿,再重新操作 发送交易: > var tx = {from: "0x391694e7e0b0cce554cb130d723a9d27458f9298", to: "0xafa3f8684e54059998bc3a7b0d2b0da075154d66", value: web3.toWei(1.23, "ether")} undefined > personal.sendTransaction(tx, "账户密码") 开启ws 参数为 地址 端口 要使用的跨域资源标头,api模块 admin.startWS("host","port","*","eth,net,web3") admin.stopWS() 以太坊浏览器 https://github.com/ethereumclassic/explorer 比较早的一个浏览器,node版本不要过高,9-10之间吧,浏览器的部署过程在git的readme中

 

最新回复(0)