智慧合約的部署,呼叫以及節點的加入
阿新 • • 發佈:2018-12-19
確保本地以安裝好go-ethernum環境
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://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
- > 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個
歡迎大家一起加入討論!!!