1. 程式人生 > >智慧合約的部署,呼叫以及節點的加入

智慧合約的部署,呼叫以及節點的加入

確保本地以安裝好go-ethernum環境

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://5a55ee4e0daaac7431cb7446a2c9fc554130768dfb1a14e726871c0e29d29ab84[email protected][::]: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://5a55ee4e0daaac7431cb7446a2c9fc554130768dfb1a14e726871c0e29d29ab84[email protected]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個

歡迎大家一起加入討論!!!