「区块链系列」搭建go-ethereum

1,611 阅读2分钟

趁着恐龙还没觉醒,我们要尽早出击!

搭建go-ethereum

加入域名收藏爱好者行列,根据区块链的域名趋势收藏起了:gohutool.com,也是“够糊涂”了。让我们的域名突破:goblockchain.top。

为何是GO,也许就是小时候街机游戏《恐龙快打》游戏配音GO! GO!趁着恐龙还没觉醒,我们要尽早出击!我们那时候只记得是“够够”游戏,长大了才知道:哦,原来叫恐龙快打!

为了增加娱乐幽默,现在我们步入正题。

下载go-ethereum

关键卡壳版本问题注意:选择的是go-ethereumv1.8.7对应的版本是go1.10.3,别卡壳找缘由,先一步步实践,后续再排查。

需要进入go的编译位置/root/go/src,然后进行下载go-ethereum,然后进行解压编译。

cd /root/go/src
wget https://github.com/ethereum/go-ethereum/archive/v1.8.7.tar.gz
tar zxvf v1.8.7.tar.gz
mv go-ethereum-1.8.7/ go-ethereum
cd go-ethereum/

构建geth需要Go(建议先使用go1.10.3版或更高版本)和C编译器。您可以使用您喜爱的包管理器安装它们。安装依赖项后,运行

make geth 

或者,要构建完整的实用程序套件

make all

环境配置

vim /etc/profile 添加配置

export GOROOT=/usr/local/go
export ETH_HOME=/root/go/src/go-ethereum/build
export PATH=$PATH:$GOROOT/bin:$ETH_HOME/bin

source /etc/profile ,然后验证:geth version

初始化创世区块

初始化创世区块时,要先创建一个 genesis.json 文件, chainId: <任意正整数>,内容如下:

{
  "config": {
    "chainId": 66,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0
  },
  "alloc": {},
  "coinbase": "0x0000000000000000000000000000000000000000",
  "difficulty": "0x20000",
  "extraData": "",
  "gasLimit": "0x2fefd8",
  "nonce": "0x0000000000000042",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp": "0x00"
}

然后使用 geth 命令初始化:

# geth init ./genesis.json --datadir "./chain"

bootnode --genkey=boot.key
bootnode --nodekey=boot.key

TODO 笔记到此,待完善 看英文文档详见README.md

Github参考:
github.com/ethereum/go…