使用系统版本:CentOS Linux release 7.9.2009 (Core)
go 版本: go1.20.2
go-ethereum 版本:1.11.4-stable
下载go
wget https://golang.google.cn/dl/go1.20.2.linux-amd64.tar.gz
解压到/usr/local目录
tar -xvf go1.17.6.linux-amd64.tar.gz -C /usr/local
将go添加到环境变量
vi /etc/profile
export GOROOT=/usr/local/go
export GOPATH=/root/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
刷新环境变量
source /etc/profile
查看版本,若有则环境变量配置成功
go version
go换源!(以免后边卡在 make geth)
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
安装基本工具开发包
yum group install "Development Tools"
查看版本
gcc --version
下载源码
cd /usr/local
git clone https://github.com/ethereum/go-ethereum.git
Building the source
make geth
查看版本号验编译
./build/bin/geth version
配环境
export GETH=/usr/local/go-ethereum
export PATH=$PATH:$GETH/build/bin
刷新环境变量
source /etc/profile
查看版本验环境
geth version
创建 genesis.json
mkdir prichain
cd prichain
mkdir data
vi genesis.json
{"config": {"chainId": ,"homesteadBlock": 0,"eip150Block": 0,"eip155Block": 0,"eip158Block": 0,"byzantiumBlock": 0,"constantinopleBlock": 0,"petersburgBlock": 0,"istanbulBlock": 0,"berlinBlock": 0,"londonBlock": 0},"alloc": {},"coinbase": "0x0000000000000000000000000000000000000000","difficulty": "0x20000","extraData": "","gasLimit": "0x2fefd8","nonce": "0x0000000000000042","mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000","parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000","timestamp": "0x00"
}
初始化传世区块
geth --datadir ./data init genesis.json
执行后会在 genesis.json的当前目录下初始化,然后执行完后会在data文件下生成两个文件夹,geth 以及 keystore,分别存放该链数据以及用户密钥
查看实时日志输出
tail -f geth.log #进入私有链所在目录
如何重新进入该链
geth --datadir --networkid 666 ./ console 2>>geth.log#666为 "chainId":后边输入的值
查看账户
eth.accounts
创建账户
personal.newAccount(”password1“)
补充:启动私有链
geth --datadir data --networkid 15 --http --http.addr 0.0.0.0 --http.port 8545 --http.corsdomain "*" --port 30305 --allow-insecure-unlock console 2>>geth.log
--datadir字段用于指示私链数据的存储位置,即工作目录;--networkid字段用于配置私链id,需要与genesis.json文件内预定义的一致;--http字段用于启用HTTP-RPC服务,主要应用于与前端页面的交互;--http.addr字段表示节点接受的http连接的地址,0.0.0.0表示可以接受所有ip地址的http请求;--http.port字段用于指定监听端口,默认是8545;--http.corsdomain字段表示允许跨域请求的域名列表,“*”表示允许所有的跨域请求,不开启的话metamask钱包可能无法连接上搭建的私链;--port字段用于指定节点之间通信的端口,默认是30303;--allow-insecure-unlock表示允许不安全的账户解锁行为,开启这个选项后通过http连接到私链的钱包才能解锁账户进行转账操作;console表示在运行私链节点的同时开启控制台,这样就可以在监控私链节点状态的同时对节点进行操作。因为geth命令运行完后会不断弹出监控日志影响到控制台的使用,因此在命令最后添加2>>geth.log就可以让监控日志输入到当前目录的geth.log文件中而不影响控制台的使用,然后在新开一个终端用tail -f geth.log的命令实时监控节点的日志即可。(如果不愿意这么麻烦可以把2>>geth.log删除)
如何安装centos详细步骤
https://blog.csdn.net/zhangjianfu2222/article/details/127443309
CentOS7设置镜像源
http://t.csdn.cn/Bc2u5
区块链笔记(1)-使用go-ethereum建立私链 geth版本 1.8.1
https://dandelioncloud.cn/article/details/1437894944882253825
以以坊私有链搭建及常用操作
https://www.cnblogs.com/mutou-mutou/articles/16174188.html
在Centos 7下使用Geth搭建自己的以太坊私有链
https://blog.csdn.net/qq_43537319/article/details/120937055
http://t.csdn.cn/smqm3
下一篇:手写LRU缓存