阅读背景:

3.6 以太坊私有链与联盟链搭建

来源:互联网 
1. 私有链搭建 1. 新建一个geth目录:mkdir geth && cd geth 2. 新建创建区块配置文件:touch genesis.json 3. 初始化 mkdir db 4. cd geth 1. geth --datadir "./db" init genesis.json 1. Geth init 初始化区块链 2. 启动节点 1. geth --datadir "./db" --rpc --rpcaddr=0.0.0.0 --rpcport 8545 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal,admin,shh,txpool,debug,miner" --nodiscover --maxpeers 30 --networkid 1981 --port 30303 --mine --minerthreads 1 --etherbase "0xcCE4c1093D63416Eb079BFfe50Dc9Ce590703c6B" console 2>>tail.log 2. 可以通过 tailf -f tail.log查看日志,如果不追加到日志中,会在当前终端窗口显示日志信息 2. 联盟链搭建 1. 配置创世区块文件 genesis.json 同一条联盟链中的所有节点必须使用同一份创世区块文件进行初始化配置 2. 初始化配置 1. 创建联盟链账户 1. Geth --datadir data account new 2. 输入两次密码后返回新账户的地址 address:{<address of new account>} 3. 将该地址复制到genesis.json的alloc参数中,可根据节点数量重复操作 4. 然后将genesis.json文件和data文件夹复制到其他节点中。 5. 在每台节点上创建联盟链节点 1. geth --datadir data init genesis.json 2. 搭建联盟链网络 1. 在每个节点上启动geth 1. geth --datadir data --networkid 15 console 2. 获取节点地址 1. admin.nodeInfo.enode 3. 将返回地址信息中的"[::]"部分替换为该节点的公网IP 4. 在每一个节点的data/geth目录下创建静态节点文件static-nodes.json,并写入其他节点的完整地址信息 5. 在每个节点机器 上使用admin.peers查看其他节点(如果没连接上可以采用"admin.addPeer("enode::<…>")"手动添加) 3. 测试 1. 挖矿 2. 解锁账户 3. 发起交易,然后 查看结果 1. 私有链搭建 1. 新建一个geth目录:mkdir geth && cd g



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: