以太坊私有链-本地多节点集群环境搭建

确保本地以安装好go-ethernum环境

未安装参考:以太坊私有链入门最新教程(6.6更新) https://blog.csdn.net/wxb880114/article/details/79202378


genesis配置文件

{
  "config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "coinbase" : "0x0000000000000000000000000000000000000000",
    "difficulty" : "0x40000",
    "extraData" : "",
    "gasLimit" : "0xffffffff",
    "nonce" : "0x0000000000000042",
    "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "timestamp" : "0x00",
    "alloc": { }
}

初始化两个节点

初始化Node1

build/bin/geth --datadir ../ethereumdata/data/00 init ./genesis.json


初始化Node2

build/bin/geth --datadir ../ethereumdata/data/01 init ./genesis.json


启动节点Node1

 build/bin/geth --datadir ../ethereumdata/data/00 --networkid 314590 --ipcdisable --port 61910 --rpcport 8200 console


查询当前节点信息



新窗口打开节点Node2

 build/bin/geth --datadir ../ethereumdata/data/01  --networkid 314590 --ipcdisable --port 61911 --rpcport 8101 --bootnodes "enode://5a55ee4e0daaac7431cb7446a2c9fc554130768dfb1a14e726871c0e29d29ab847258596611adba6c5928e653b0bbefb0a8d4d141094621b512cadefbb8f7219@[::]:61910" console

修改ip地址 127.0.0.1

扫描二维码关注公众号,回复: 1766269 查看本文章


启动成功

当启动Node1时,peers为0


启动Node2并将Node1添加到bootnodes中去

Node1执行 admin.peers()


Node2执行admin.peers



再加一个节点Node3

build/bin/geth --datadir ../ethereumdata/data/02 init ./genesis.json

启动Node3

build/bin/geth --datadir ../ethereumdata/data/02  --networkid 314590 --ipcdisable --port 61912 --rpcport 8102 --bootnodes "enode://5a55ee4e0daaac7431cb7446a2c9fc554130768dfb1a14e726871c0e29d29ab847258596611adba6c5928e653b0bbefb0a8d4d141094621b512cadefbb8f7219@127.0.0.1:61910" console

再查询Node1的 admin.peers



Node2 admin.peers

> admin.peers
[{
    caps: ["eth/63"],
    id: "5a55ee4e0daaac7431cb7446a2c9fc554130768dfb1a14e726871c0e29d29ab847258596611adba6c5928e653b0bbefb0a8d4d141094621b512cadefbb8f7219",
    name: "Geth/v1.8.11-unstable-c8dcb958/linux-amd64/go1.9.2",
    network: {
      inbound: false,
      localAddress: "127.0.0.1:41672",
      remoteAddress: "127.0.0.1:61910",
      static: false,
      trusted: false
    },
    protocols: {
      eth: {
        difficulty: 262144,
        head: "0xa0e580c6769ac3dd80894b2a256164a76b796839d2eb7f799ef6b9850ea5e82e",
        version: 63
      }
    }
}, {
    caps: ["eth/63"],
    id: "96fc9a1f96b1fa14ee77508da282bd4a5e16dfe506ff9d6257a1ccfffa6b4a028fdd6029f00d097808b89183be36302eddb5024c6f5ca479b0e79add60396016",
    name: "Geth/v1.8.11-unstable-c8dcb958/linux-amd64/go1.9.2",
    network: {
      inbound: false,
      localAddress: "127.0.0.1:44958",
      remoteAddress: "127.0.0.1:61912",
      static: false,
      trusted: false
    },
    protocols: {
      eth: {
        difficulty: 262144,
        head: "0xa0e580c6769ac3dd80894b2a256164a76b796839d2eb7f799ef6b9850ea5e82e",
        version: 63
      }
    }
}, {
    caps: ["eth/62", "eth/63"],
    id: "ecdff424d3be0b827851299f5a386865f11261a4e1049e5994610e958411d706a9371391b0559fe7a49b765d0643db42d618c9f6bca767a5bcaad64b33a71152",
    name: "Geth/v4.1.0/linux/go1.8",
    network: {
      inbound: false,
      localAddress: "172.17.89.241:44984",
      remoteAddress: "13.124.73.10:30303",
      static: false,
      trusted: false
    },
    protocols: {
      eth: "handshake"
    }
}]

Node3节点 admin.peers

[{
    caps: ["eth/63"],
    id: "5a55ee4e0daaac7431cb7446a2c9fc554130768dfb1a14e726871c0e29d29ab847258596611adba6c5928e653b0bbefb0a8d4d141094621b512cadefbb8f7219",
    name: "Geth/v1.8.11-unstable-c8dcb958/linux-amd64/go1.9.2",
    network: {
      inbound: false,
      localAddress: "127.0.0.1:43600",
      remoteAddress: "127.0.0.1:61910",
      static: false,
      trusted: false
    },
    protocols: {
      eth: {
        difficulty: 262144,
        head: "0xa0e580c6769ac3dd80894b2a256164a76b796839d2eb7f799ef6b9850ea5e82e",
        version: 63
      }
    }
}, {
    caps: ["eth/63"],
    id: "e39df925c43c22915c92d0a09f1f9675bd4e20439ef6da0e91dffa62a0413fe4b45726aaeeac0ff39e334e5d766856f74b6328f5d2b93da74fbad2d7a577c663",
    name: "Geth/v1.8.11-unstable-c8dcb958/linux-amd64/go1.9.2",
    network: {
      inbound: true,
      localAddress: "127.0.0.1:61912",
      remoteAddress: "127.0.0.1:44958",
      static: false,
      trusted: false
    },
    protocols: {
      eth: {
        difficulty: 262144,
        head: "0xa0e580c6769ac3dd80894b2a256164a76b796839d2eb7f799ef6b9850ea5e82e",
        version: 63
      }
    }
}]
INFO [06-20|15:22:10] Updated mining threads                   threads=0
INFO [06-20|15:22:10] Transaction pool price threshold updated price=18000000000
ERROR[06-20|15:22:10] Cannot start mining without etherbase    err="etherbase must be explicitly specified"
Error: etherbase missing: etherbase must be explicitly specified
    at web3.js:3143:20
    at web3.js:6347:15
    at web3.js:5081:36
    at <anonymous>:1:1

原因是当前环境没有账户,需要建立一个账户

解决:personal.newAccount("xxx"), 这里创建一个新账户, 注意有的同学会疑问以前都有账户啊,怎么现在没啦,可能你启动geth的路径有问题

Node1 创建账号

personal.newAccount("111111")

Node2 创建账号

personal.newAccount("123")

开始转账交易

> eth.sendTransaction({from: "0xac3391fb5d712f656e60af7e040ea47f92bf9d0b", to: "0xed35c55e6b7b3760bffb959722cdbaf5479ded41", value: web3.toWei(1, "ether")})
Error: authentication needed: password or unlock
    at web3.js:3143:20
    at web3.js:6347:15
    at web3.js:5081:36
    at <anonymous>:1:1

> personal.unlockAccount(eth.accounts[0],"111111")


 eth.sendTransaction({from: "0x861e9d6be38d8b44acb91c8cbabb045076f1c185", to: "0x3da1dc8ecc88dc821ea89ab309bfe4152dbc5504", value: web3.toWei(1, "ether")})
Error: insufficient funds for gas * price + value
    at web3.js:3143:20
    at web3.js:6347:15
    at web3.js:5081:36
    at <anonymous>:1:1

当前账户余额不足

转账操作只有在启动挖矿后才能生效,切记!!!!


转账15个





欢迎大家一起加入讨论!!!


猜你喜欢

转载自blog.csdn.net/wxb880114/article/details/80742672