码迷,mamicode.com
首页 > 其他好文 > 详细

ETH 私链搭建

时间:2018-08-11 01:40:23      阅读:395      评论:0      收藏:0      [点我收藏+]

标签:工具   network   cap   dmi   install   ada   表示   三台   $path   

一.下载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://cc21a7d2d54587fbac48cc6ae942918fb6e833811dc2ee8acbecb0a32072273489cf8b863e358b6136ab97774477ee63fe7850d184ba3aca869b190551047066@[::]: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://d0aa73f9dbf892ad5ca9fd9a12c67622603b8b126616730d7d202a76edc9a51341b8c3c173a48b3897c11af1b0f4d07fd63122c0dfa9b57cf46b2cb0806ed91f@[::]:30301
enode://545e112d84633ad17c537bd402a87cf17572b5efb5c4e639c88fc16ce41795b28bc1d0ba9f4e4406284566ac88480c9f15651c140f0a37db521beecffe79efa2@[::]:30301

  将它们加入到机器一的连接中,在机器一中接着运行:

admin.addPeer("enode://d0aa73f9dbf892ad5ca9fd9a12c67622603b8b126616730d7d202a76edc9a51341b8c3c173a48b3897c11af1b0f4d07fd63122c0dfa9b57cf46b2cb0806ed91f@[::]:30301")
admin.addPeer("enode://545e112d84633ad17c537bd402a87cf17572b5efb5c4e639c88fc16ce41795b28bc1d0ba9f4e4406284566ac88480c9f15651c140f0a37db521beecffe79efa2@[::]: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 私链搭建

标签:工具   network   cap   dmi   install   ada   表示   三台   $path   

原文地址:https://www.cnblogs.com/hbright/p/9457924.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!