智能合约的部署,调用以及节点的加入

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wxb880114/article/details/80742672

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

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


genesis配置文件

  1. {
  2. "config": {
  3. "chainId": 15,
  4. "homesteadBlock": 0,
  5. "eip155Block": 0,
  6. "eip158Block": 0
  7. },
  8. "coinbase" : "0x0000000000000000000000000000000000000000",
  9. "difficulty" : "0x40000",
  10. "extraData" : "",
  11. "gasLimit" : "0xffffffff",
  12. "nonce" : "0x0000000000000042",
  13. "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  14. "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  15. "timestamp" : "0x00",
  16. "alloc": { }
  17. }

初始化两个节点

初始化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


启动成功

当启动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

  1. > admin.peers
  2. [{
  3. caps: ["eth/63"],
  4. id: "5a55ee4e0daaac7431cb7446a2c9fc554130768dfb1a14e726871c0e29d29ab847258596611adba6c5928e653b0bbefb0a8d4d141094621b512cadefbb8f7219",
  5. name: "Geth/v1.8.11-unstable-c8dcb958/linux-amd64/go1.9.2",
  6. network: {
  7. inbound: false,
  8. localAddress: "127.0.0.1:41672",
  9. remoteAddress: "127.0.0.1:61910",
  10. static: false,
  11. trusted: false
  12. },
  13. protocols: {
  14. eth: {
  15. difficulty: 262144,
  16. head: "0xa0e580c6769ac3dd80894b2a256164a76b796839d2eb7f799ef6b9850ea5e82e",
  17. version: 63
  18. }
  19. }
  20. }, {
  21. caps: ["eth/63"],
  22. id: "96fc9a1f96b1fa14ee77508da282bd4a5e16dfe506ff9d6257a1ccfffa6b4a028fdd6029f00d097808b89183be36302eddb5024c6f5ca479b0e79add60396016",
  23. name: "Geth/v1.8.11-unstable-c8dcb958/linux-amd64/go1.9.2",
  24. network: {
  25. inbound: false,
  26. localAddress: "127.0.0.1:44958",
  27. remoteAddress: "127.0.0.1:61912",
  28. static: false,
  29. trusted: false
  30. },
  31. protocols: {
  32. eth: {
  33. difficulty: 262144,
  34. head: "0xa0e580c6769ac3dd80894b2a256164a76b796839d2eb7f799ef6b9850ea5e82e",
  35. version: 63
  36. }
  37. }
  38. }, {
  39. caps: ["eth/62", "eth/63"],
  40. id: "ecdff424d3be0b827851299f5a386865f11261a4e1049e5994610e958411d706a9371391b0559fe7a49b765d0643db42d618c9f6bca767a5bcaad64b33a71152",
  41. name: "Geth/v4.1.0/linux/go1.8",
  42. network: {
  43. inbound: false,
  44. localAddress: "172.17.89.241:44984",
  45. remoteAddress: "13.124.73.10:30303",
  46. static: false,
  47. trusted: false
  48. },
  49. protocols: {
  50. eth: "handshake"
  51. }
  52. }]

Node3节点 admin.peers

  1. [{
  2. caps: ["eth/63"],
  3. id: "5a55ee4e0daaac7431cb7446a2c9fc554130768dfb1a14e726871c0e29d29ab847258596611adba6c5928e653b0bbefb0a8d4d141094621b512cadefbb8f7219",
  4. name: "Geth/v1.8.11-unstable-c8dcb958/linux-amd64/go1.9.2",
  5. network: {
  6. inbound: false,
  7. localAddress: "127.0.0.1:43600",
  8. remoteAddress: "127.0.0.1:61910",
  9. static: false,
  10. trusted: false
  11. },
  12. protocols: {
  13. eth: {
  14. difficulty: 262144,
  15. head: "0xa0e580c6769ac3dd80894b2a256164a76b796839d2eb7f799ef6b9850ea5e82e",
  16. version: 63
  17. }
  18. }
  19. }, {
  20. caps: ["eth/63"],
  21. id: "e39df925c43c22915c92d0a09f1f9675bd4e20439ef6da0e91dffa62a0413fe4b45726aaeeac0ff39e334e5d766856f74b6328f5d2b93da74fbad2d7a577c663",
  22. name: "Geth/v1.8.11-unstable-c8dcb958/linux-amd64/go1.9.2",
  23. network: {
  24. inbound: true,
  25. localAddress: "127.0.0.1:61912",
  26. remoteAddress: "127.0.0.1:44958",
  27. static: false,
  28. trusted: false
  29. },
  30. protocols: {
  31. eth: {
  32. difficulty: 262144,
  33. head: "0xa0e580c6769ac3dd80894b2a256164a76b796839d2eb7f799ef6b9850ea5e82e",
  34. version: 63
  35. }
  36. }
  37. }]
  1. INFO [06-20|15:22:10] Updated mining threads                   threads=0
  2. INFO [06-20|15:22:10] Transaction pool price threshold updated price=18000000000
  3. ERROR[06-20|15:22:10] Cannot start mining without etherbase    err="etherbase must be explicitly specified"
  4. Error: etherbase missing: etherbase must be explicitly specified
  5.     at web3.js:3143:20
  6.     at web3.js:6347:15
  7.     at web3.js:5081:36
  8.     at <anonymous>:1:1

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

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

Node1 创建账号

personal.newAccount("111111")

Node2 创建账号

personal.newAccount("123")

开始转账交易

  1. > eth.sendTransaction({from: "0xac3391fb5d712f656e60af7e040ea47f92bf9d0b", to: "0xed35c55e6b7b3760bffb959722cdbaf5479ded41", value: web3.toWei(1, "ether")})
  2. Error: authentication needed: password or unlock
  3. at web3.js:3143:20
  4. at web3.js:6347:15
  5. at web3.js:5081:36
  6. at <anonymous>:1:1
  7. > personal.unlockAccount(eth.accounts[0],"111111")


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

当前账户余额不足

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


转账15个





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


展开阅读全文

没有更多推荐了,返回首页