操作系统:Ubuntu18.04
目录
1.安装geth
sudo add-apt-repository -y ppa:ethereum/ethereum
//libappstream3 可能导致update失败,先删除
update
sudo apt-get purge libappstream3
sudo apt-get update
sudo apt-get install ethereum
2.创建创世区块
mkdir -p ~/privateChainTest/data0
建立创世区块genesis.json
{
"config": {
"chainID": 2019
},
"alloc": {
"0xeced0f2076c6f790173f38012f130a9e5c493a95": {
"balance": "100000000000000000000000000"
}
},
"coinbase": "0x0000000000000000000000000000000000000000",
"difficulty": "0x400",
"extraData": "",
"gasLimit": "0x2fefd8",
"nonce": "0xdeadbeefdeadbeef",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x00"
}
3.初始化创世区块
cd privateChain
geth --datadir data0 init genesis.json
4.启动私链
geth --identity "qtlnode" --targetgaslimit 4294967295 --gasprice 1000000000 --rpc --rpcport "8545" --rpcaddr 0.0.0.0 --rpccorsdomain "*" --datadir data0 --port "30303" console
5.新建账户
personal.newAccount()
6.挖矿
miner.start()
7.停止
miner.stop()
8.查看本节点信息
admin.nodeInfo
9.向本节点添加其他P2P节点信息
admin.addPeer("enode://f2c91ee24585e592fa5adc1940360b90e1a10969c5955fc51807bb24ab5e34265994c36f3af51a982a3d6d66f73b8cbba99ad38739545812724d60bf5c58e684@192.168.0.111:30303")
10.解锁需要向外转账的账户
personal.unlockAccount()
11.向他人转账
eth.sendTransaction({from:本节点账号,to:对方账号,value:转账数量})
eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:100000000000000000})
11.其他
geth启动可以加
--verbosity "2"来关闭log输出
geth --verbosity "2" --identity "qtlnode" --targetgaslimit 4294967295 --gasprice 1000000000 --rpc --rpcport "8545" --rpcaddr 0.0.0.0 --rpccorsdomain "*" --datadir data0 --port "30303" console
附:以太坊客户端Geth命令详解:https://www.jianshu.com/p/5783b59a4501