go-ethereum钱包环境搭建以及同步测试链区块的示例分析

今天就跟大家聊聊有关go-ethereum钱包环境搭建以及同步测试链区块的示例分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

应公司要求,要接入ETH,该文章讲解如何在ubuntu环境搭建go-ethereum

环境要求:

linux系统:ubuntu、8 GB内存、500 GB硬盘(SSD更好)、4个vCPU(2个v勉强凑合)

当前测试链区块数据大小:8.8G,笔者这个配置同步了接近一上午的时间(10M带宽)

相关依赖:
    go-version:1.10.1
    git-version:2.7.4      2.0以上均可
    geth-version:1.8.9

1.安装git

# Ubuntu默认安装 2.7.4
sudo apt-get install git

2.安装go

wget https://studygolang.com/dl/golang/go1.10.1.linux-amd64.tar.gz
tar -zxvf go1.10.1.linux-amd64.tar.gz
mv go /usr/local/

# 添加环境变量
echo "export GOROOT=/usr/local/go" >> /etc/profile
echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
source /etc/profile

3.安装geth(go-ethereum)

git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum/

gmake all
# 报错“gmake:未找到命令”
# 解决方案:cd /usr/bin && sudo ln -s make gmake

# 报错vendor/github.com/karalabe/hid/hidapi/libusb/hid.c:444: undefined reference to `libiconv_open'
  vendor/github.com/karalabe/hid/hidapi/libusb/hid.c:456: undefined reference to `libiconv'
  vendor/github.com/karalabe/hid/hidapi/libusb/hid.c:471: undefined reference to `libiconv_close'
  collect2: ld returned 1 exit status
  util.go:45: exit status 2
  exit status 1
  make: *** [geth] Error 1
#解决方案:mv /usr/local/include/iconv.h /usr/local/include/iconv.h.back

echo "export PATH=$PATH:/home/adamson/go-ethereum/build/bin" >> /etc/profile
source /etc/profile

请确认您已经安装好了以上三项再继续下面的内容。

4.同步测试链(rinkeby)数据

geth --syncmode "fast" --datadir "/currency/eth/data-sync/test-rinkeby"  --rinkeby --cache=512 console

命令描述:

fast    快速同步模式(只同步区块头,而不同步区块体)

--datadir    同步数据的目录(目录需要手动添加,目录名随意命名)

--rinkeby    同步rinkeby测试链上的数据

--cache    缓存值,最低16mb,默认128

console    已控制台的方式运行

根据每个人需求不同,使用的同步命令也会不一样。

正确同步区块,如下图:

go-ethereum钱包环境搭建以及同步测试链区块的示例分析

请耐心等待,这需要一会儿时间。。。

区块同步成功,如下图:

go-ethereum钱包环境搭建以及同步测试链区块的示例分析

如果出现了红框中的字样说明已经同步成功,恭喜你已经完成数据同步!

看完上述内容,你们对go-ethereum钱包环境搭建以及同步测试链区块的示例分析有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。