ETH 私链搭建
Posted hbright
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ETH 私链搭建相关的知识,希望对你有一定的参考价值。
一.下载ETH源码
github网址: https://github.com/ethereum/go-ethereum
二.编译
1.首先下载ETH相关的工具
sudo add-apt-repository -y ppa:ethereum/ethereum sudo apt-get update sudo apt-get install ethereum
2.下载golang
https://golang.google.cn/dl/
下载后解压到/usr/local/go,然后在/usr/profile中添加环境变量 :
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
3.编译
cd go-ethereum
make geth
三. 环境配置与运行
1.编写genesis.json文件,放到~/config下面,内容如下:
{ "config": { "chainId": 10, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "alloc" : {}, "coinbase" : "0x0000000000000000000000000000000000000000", "difficulty" : "0x02000000", "extraData" : "", "gasLimit" : "0x2fefd8", "nonce" : "0x0000000000000042", "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp" : "0x00" }
2.运行节点
geth --datadir ~/ether/n1 init genesis.json geth --identity "hello" --datadir ~/ether/n1 --port 30301 --rpcport 8101 --networkid 12345 console 2>> ~/ether/n1/geth.log
成功后再获取节点信息:
> admin.nodeInfo { enode: "enode://cc21a7d2d54587fbac48cc6ae942918fb6e833811dc2ee8acbecb0a3207227348[email protected][::]:30301", id: "cc21a7d2d54587fbac48cc6ae942918fb6e833811dc2ee8acbecb0a32072273489cf8b863e358b6136ab97774477ee63fe7850d184ba3aca869b190551047066", ip: "::", listenAddr: "[::]:30301", name: "Geth/hello/v1.8.12-stable-37685930/linux-amd64/go1.10", ports: { discovery: 30301, listener: 30301 }, protocols: { eth: { config: { chainId: 10, eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000", eip155Block: 0, eip158Block: 0, homesteadBlock: 0 }, difficulty: 33554432, genesis: "0xbf289100224ae9e27375b93509ff30b7624af5e8ae3eae472e814a2dd6ad1419", head: "0xbf289100224ae9e27375b93509ff30b7624af5e8ae3eae472e814a2dd6ad1419", network: 12345 } } }
将第二台和第三台的机器按照上面的步骤部署,
机器二和机器三的encode:
enode://d0aa73f9dbf892ad5ca9fd9a12c67622603b8b126616730d7d202a76edc9a5134[email protected][::]:30301
enode://545e112d84633ad17c537bd402a87cf17572b5efb5c4e639c88fc16ce41795b28[email protected][::]:30301
将它们加入到机器一的连接中,在机器一中接着运行:
admin.addPeer("enode://d0aa73f9dbf892ad5ca9fd9a12c67622603b8b126616730d7d202a76edc9a5134[email protected][::]:30301") admin.addPeer("enode://545e112d84633ad17c537bd402a87cf17572b5efb5c4e639c88fc16ce41795b28[email protected][::]:30301")
再查看连接信息:
> net.peerCount 2 > admin.peers [{ caps: ["eth/61", "eth/62", "eth/63"], id: "07954219f1a52acfa7562ac841e77860505bb6f6cc948bc540b94326606679d33e805a21b21cb105eaf58f449b0acc84893560919afee00bbc01b8a3fc0213af", name: "Geth/v1.4.5-stable-a269a713/linux/go1.6.2/hello", network: { localAddress: "219.216.65.127:30301", remoteAddress: "219.216.64.144:36332" }, protocols: { eth: { difficulty: 5290384, head: "337f2059a1a6d82aee1afba91828d86a8a3b6f85d83b8cb2f8a9210af3b29c1c", version: 63 } } }, { caps: ["eth/61", "eth/62", "eth/63"], id: "54b7b1dccbe37148cda6e0c9889d23ffb8e2efc905f3c2d001cd66b3b513210a4a426706bab795d83d0c236b9b1647f46947d86c48ac8faf7f802aff318c4aa1", name: "Geth/v1.4.5-stable/windows/go1.6.2/hello", network: { localAddress: "219.216.65.127:30301", remoteAddress: "219.216.65.139:50911" }, protocols: { eth: { difficulty: 5290384, head: "337f2059a1a6d82aee1afba91828d86a8a3b6f85d83b8cb2f8a9210af3b29c1c", version: 63 } } }]
表示连接成功,至此结束。
以上是关于ETH 私链搭建的主要内容,如果未能解决你的问题,请参考以下文章