测试环境
1.拉取代码
cd /usr/local
git clone https://github.com/ethereum/go-ethereum.git
切换分支
查看当前分支
编译geth
设置软链接
ln -s /usr/local/go-ethereum/build/bin/geth geth
ln -s /usr/local/go-ethereum/build/bin/bootnode bootnode
查看版本
2.搭建私链
创建数据目录
cd /mnt
mkdir myeth
cd mygeth
mkdir node1
创建账号
geth --datadir node1/ account new
记录账号密码
echo "0x00000000000000000000000000000000" >> account.txt
echo '1234' > node1/password.txt
创建创始区块文件
内容
{
"config": {
"chainId": 7874,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"berlinBlock": 0,
"londonBlock": 0
},
"alloc": {},
"nonce": "0x0000000000000042",
"difficulty": "0x20000",
"coinbase": "0x000000000000000000000000000000000",
"extraData": "",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x2fefd8",
"timestamp": "0x00"
}
查看当前目录
初始化私链
geth --datadir node1 init genesis.json
编写启动脚本(vim genesis.json)
geth --datadir /mnt/myeth/node1 --identity "node1" --networkid 7874 --http --http.addr "127.0.0.1" --http.port 8545 --http.api "eth,net,web3,personal,miner" --mine --miner.threads=1 --miner.etherbase=0x0000000000000000000000000000000000000000 --allow-insecure-unlock --unlock "0x00000000000000000000000000000000000" --password node1/password.txt > node1.log 2>&1 &
编写控制台脚本(vim console1.sh)
geth attach ipc:/mnt/myeth/node1/geth.ipc
修改权限
chmod u+rwx ./node1.sh ./console1.sh
启动脚本
./node1.sh && ./console1.sh