1. 服务器角色分配:
ip地址 角色
10.0.0.11 主节点
10.0.0.12 同步节点
  1. 下载(主节点和同步节点均要执行此操作):
    wget https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.25-e7872729.tar.gz

  2. 解压(主节点和同步节点均要执行此操作):
    tar -xzf geth-linux-amd64-1.9.25-e7872729.tar.gz --warning=no-timestamp

  3. 添加到可执行路径(主节点和同步节点均要执行此操作):
    cp geth-linux-amd64-1.9.25-e7872729/geth /usr/bin/

  4. 创建配置文件(主节点和同步节点均要执行此操作):
    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"
             }
         }
     }
  5. 初始化(主节点和同步节点均要执行此操作):
    geth --datadir data init genesis.json

  6. 启动服务(主节点和同步节点均要执行此操作):

     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
  7. 启动客户端(主节点和同步节点均要执行此操作):
    geth attach ipc:http://10.0.0.11:8200

  8. 查看enode(主节点):
    admin.nodeInfo.enode

  9. 加入主节点(同步节点):
    admin.addPeer("enode://70b4ad13d25f6100227cc99324b2bb0017134a9da7f4ff1fac02415e414ea6e8096612e501d4f2bf3009c1332e7243a79224834616f7b5819de7e5f42d593adf@10.0.0.11:61910")

  10. 查看节点信息(主节点和同步节点均可执行此操作):
    admin.peers

  11. 基本操作:

    1. 查看所有账号:
      eth.accounts
    2. 添加新账号:
      personal.newAccount("mypassword")
    3. 查看矿工账号:
      eth.coinbase
    4. 开始挖矿:
      miner.start()
    5. 停止挖矿:
      miner.stop()
    6. 查看矿工余额:
      web3.fromWei(eth.getBalance(eth.accounts[0]))
    7. 转账:
      personal.unlockAccount(eth.accounts[0])
      eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(8,'ether')})
文档更新时间: 2024-04-20 10:57   作者:lee