Geth官网:https://geth.ethereum.org/
Geth的Github地址:https://github.com/ethereum/go-ethereum
一:安装Geth
1.进入官网获取最新版本
2.获取安装包并解压
wget https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.25-e7872729.tar.gz
tar -zxvf geth-linux-amd64-1.9.25-e7872729.tar.gz
3.将Geth加入环境变量
本人下载后加压安装包路径如下:/home/gethSourceCode/geth-linux-amd64-1.9.25-e7872729
echo 'export PATH=$PATH:/home/gethSourceCode/geth-linux-amd64-1.9.25-e7872729' >> /etc/profile
source /etc/profile
成功后
二:初始化私有链
1.在这里我新建一个文件夹myChain用来创建初始化创世链
2.进入myChain编写文件
vim genesis.json
这里我将本账号的以太币初始化为10000000000000000wei,方便以后测试用
{
"config": {
"chainId": 20
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x40000",
"extraData" : "",
"gasLimit" : "0xffffffff",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc": {
"metamask账户":{"balance":"10000000000000000000000"}
}
3.新建data/demo用来存放数据,并初始化创世链
geth --datadir ./data/demo init genesis.json
4.启动网络
rpcaddr 是服务器的内网ip
geth --datadir data --rpc --rpcaddr "172.25.12.132" --rpcport "8545" --rpcapi "eth,web3,miner,admin,personal,net" --rpccorsdomain "*" --nodiscover --networkid 22 console 2>output.log
三:使用MetaMask连接私有链
记得在服务器的控制台将8545端口开放防火墙
ip为公网ip
如果networkid填入id报错,并且返回一个id,那就将返回的id填入
结果: