- 服务器角色分配:
ip地址 | 角色 |
---|---|
10.0.0.11 | 主节点 |
10.0.0.12 | 同步节点 |
下载(主节点和同步节点均要执行此操作):
wget https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.25-e7872729.tar.gz
解压(主节点和同步节点均要执行此操作):
tar -xzf geth-linux-amd64-1.9.25-e7872729.tar.gz --warning=no-timestamp
添加到可执行路径(主节点和同步节点均要执行此操作):
cp geth-linux-amd64-1.9.25-e7872729/geth /usr/bin/
创建配置文件(主节点和同步节点均要执行此操作):
vim genesis.json
{ "config": { "chainId": 1001, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 0, "constantinopleBlock": 0, "petersburgBlock": 0 }, "coinbase": "0x0000000000000000000000000000000000000000", "difficulty": "0x20", "gasLimit": "0xffffffff", "nonce": "0x0000000000000042", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x00", "alloc": { "0xef6a214542A5371F321a3e457EeC76DA2b4b3C34": { "balance": "0x100000000000000000" } } }
初始化(主节点和同步节点均要执行此操作):
geth --datadir data init genesis.json
启动服务(主节点和同步节点均要执行此操作):
geth --datadir data \ --rpc \ --rpcapi eth,web3,miner,admin,personal,net \ --ipcdisable \ --rpccorsdomain "*" \ --rpcaddr="10.0.0.11" \ --rpcport 8200 \ --ws \ --wsaddr 10.0.0.11 \ --wsapi eth,web3 \ --wsorigins '*' \ --wsport 8300 \ --port 61910 \ --networkid 15 \ --nousb \ --allow-insecure-unlock
启动客户端(主节点和同步节点均要执行此操作):
geth attach ipc:http://10.0.0.11:8200
查看
enode
(主节点):admin.nodeInfo.enode
加入主节点(同步节点):
admin.addPeer("enode://70b4ad13d25f6100227cc99324b2bb0017134a9da7f4ff1fac02415e414ea6e8096612e501d4f2bf3009c1332e7243a79224834616f7b5819de7e5f42d593adf@10.0.0.11:61910")
查看节点信息(主节点和同步节点均可执行此操作):
admin.peers
基本操作:
- 查看所有账号:
eth.accounts
- 添加新账号:
personal.newAccount("mypassword")
- 查看矿工账号:
eth.coinbase
- 开始挖矿:
miner.start()
- 停止挖矿:
miner.stop()
- 查看矿工余额:
web3.fromWei(eth.getBalance(eth.accounts[0]))
- 转账:
personal.unlockAccount(eth.accounts[0]) eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(8,'ether')})
- 查看所有账号: