Geth + mist+私有链部署智能合约-5.2

genesis.json文件

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

据此创建创世块,并开始挖矿miner.start(1) ,再停止挖矿后,eth.coinbase主账户中就有了ether,这次得到以太的挖矿到底打包了什么交易?
参考https://www.cnblogs.com/sumingk/articles/9030469.html的配置新节点出现错误提示
配置如下命令
geth --identity "TestNode2" --datadir "data1" --rpc --rpcapi "db,eth,net,web3" --rpcaddr "127.0.0.1" --ipcpath "data1\geth\geth.ipc" --rpcport "8487" --port "30305" --networkid "29382" console

UDP listener upself=enode://c00f076d0bee45cbfbc5d301ce90c31f1cc55bbbfe5b85619e46804570013ddd18937d08550a322e087469439dc3cff39c1ce139de6535bf7cd1c16542eb32e2@[::]:30303 Fatal: Error starting protocol stack: listen tcp :30303: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

每允许使用一个socket地址。
然鹅,使用参考链接给出的命令就可以成功启动节点,dont know why...
geth --identity "TestNode2" --datadir "data1" --rpc --rpcapi "db,eth,net,web3" --rpcaddr "127.0.0.1" --ipcpath "data1\geth\geth.ipc" --rpcport "8487" --port "30305" --networkid "29382" console

JS控制台已经启动
instance: Geth/TestNode2/v1.8.11-stable-dea1ce05/windows-amd64/go1.10.2 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

在主节点上添加新节点失败
> admin.addpeer("enode://5de4cb1aa4aaa9f2e1feb40c0a6745e1ec729313497489466509e7ed2058550c76292e630ed0e2a283a992ff7bed4b9f1f30b06e952b30e973909cdd5df7ea7d@[::]:30305")TypeError: 'addpeer' is not a function at :1:1> web3.admin.addpeer("enode://5de4cb1aa4aaa9f2e1feb40c0a6745e1ec729313497489466509e7ed2058550c76292e630ed0e2a283a992ff7b ed4b9f1f30b06e952b30e973909cdd5df7ea7d@[::]:30305") TypeError: 'addpeer' is not a function at :1:1

这个是因为admin.addpeer应该是admin.addPeer
与参考链接不同的地方在于主节点,重新启动一个主节点
geth --identity "TestNode1" --datadir "data0" --rpc --rpcapi "db,eth,net,web3" --rpcaddr "127.0.0.1" --rpcport "8486" --port "30304" --networkid "29382" console

==========================================分割线===============================================
【Geth + mist+私有链部署智能合约-5.2】用上面的genesis.json文件参考链接新建两个节点
分别启动两个节点
#dos窗口1 geth --identity "testNode1" --datadir "data0" --rpc --rpcapi "db,eth,net,web3" --rpcaddr "127.0.0.1" --rpcport "8486" --port "30304" --networkid "29382" console #dos窗口2 geth --identity "testNode2" --datadir "data1" --rpc --rpcapi "db,eth,net,web3" --rpcaddr "127.0.0.1" --ipcpath "data1\geth\geth.ipc" --rpcport "8487" --port "30305" --networkid "29382" console

admin.nodeInfo { enode: "enode://6f7d8a0caa1d40c04c8c9b9b4e0a42ac4591b815b17f2ea16d2c1e460287e8fbb81e1c96e4f739331cce0df278e3487b91e0640908b522ccf9e10892b35a708e@[::]:30304", id: "6f7d8a0caa1d40c04c8c9b9b4e0a42ac4591b815b17f2ea16d2c1e460287e8fbb81e1c96e4f739331cce0df278e3487b91e0640908b522ccf9e10892b35a708e", ip: "::", listenAddr: "[::]:30304", name: "Geth/testNode1/v1.8.11-stable-dea1ce05/windows-amd64/go1.10.2", ports: { discovery: 30304, listener: 30304 }, protocols: { eth: { config: { chainId: 13, eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000", eip155Block: 0, eip158Block: 0, homesteadBlock: 0 }, difficulty: 768, genesis: "0x9de6c673941ebfa13a4494828e24cb206556386ef81249a65e203588be457315", head: "0x9de6c673941ebfa13a4494828e24cb206556386ef81249a65e203588be457315", network: 29382 } } } > personal.newAccount("123456") "0xa86c4c8864edf91fe0be416f7e252e90ade98a60" > personal.newAccount("123456") "0x642b43d11fe2cdf725a8970b7342c530bcc363f2" > personal.newAccount("123456") "0xaf07e1acba2194de5636a65e3df84b8bfc328431" > eth.coinbase INFO [07-31|22:44:24] Etherbase automatically configuredaddress=0xA86C4C8864Edf91fe0bE416f7e252e90ADE98A60 "0xa86c4c8864edf91fe0be416f7e252e90ade98a60" > eth.getBalance(eth.accounts[0]) 0 > miner.start() INFO [07-31|22:44:56] Updated mining threadsthreads=0 INFO [07-31|22:44:56] Transaction pool price threshold updated price=18000000000 nuIlNlF O > [07-31|22:44:56] Starting mining operation INFO [07-31|22:44:56] Commit new mining worknumber=1 txs=0 uncles=0 elapsed=0s INFO [07-31|22:44:57] Successfully sealed new blocknumber=1 hash=990403…0f3b42 INFO [07-31|22:44:57]

testNode2节点
admin.nodeInfo { enode: "enode://c539b7f91a709d9590121fbf4518ee1632d2999f1d67408c864bd2fab968376b39d1167871ccd1a2468bbdb89681404f2f2686722830897c75c13e45acc94a07@[::]:30305", id: "c539b7f91a709d9590121fbf4518ee1632d2999f1d67408c864bd2fab968376b39d1167871ccd1a2468bbdb89681404f2f2686722830897c75c13e45acc94a07", ip: "::", listenAddr: "[::]:30305", name: "Geth/testNode2/v1.8.11-stable-dea1ce05/windows-amd64/go1.10.2", ports: { discovery: 30305, listener: 30305 }, protocols: { eth: { config: { chainId: 13, eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000", eip155Block: 0, eip158Block: 0, homesteadBlock: 0 }, difficulty: 19416440, genesis: "0x9de6c673941ebfa13a4494828e24cb206556386ef81249a65e203588be457315", head: "0x444e9e4878a105b396d1caebdbf5c56023f88bf3874c7bd9528fc3e2ec2082fb", network: 29382 } } } >

分别注册3个账户后,分别miner.start(1),会确认一些交易得到以太币;在testNode2窗口添加testNode1节点
testNode1节点的账户,账户密码设置成123456
> admin.nodeInfo { enode: "enode://6f7d8a0caa1d40c04c8c9b9b4e0a42ac4591b815b17f2ea16d2c1e460287e8fbb81e1c96e4f739331cce0df278e3487b91e0640908b522ccf9e10892b35a708e@[::]:30304", id: "6f7d8a0caa1d40c04c8c9b9b4e0a42ac4591b815b17f2ea16d2c1e460287e8fbb81e1c96e4f739331cce0df278e3487b91e0640908b522ccf9e10892b35a708e", ip: "::", listenAddr: "[::]:30304", name: "Geth/testNode1/v1.8.11-stable-dea1ce05/windows-amd64/go1.10.2", ports: { discovery: 30304, listener: 30304 }, protocols: { eth: { config: { chainId: 13, eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000", eip155Block: 0, eip158Block: 0, homesteadBlock: 0 }, difficulty: 26119992, genesis: "0x9de6c673941ebfa13a4494828e24cb206556386ef81249a65e203588be457315", head: "0xccc4b409a7d29a6bf224acadf33dd9c581b3fba2b2460e2cc42b865200d0524c", network: 29382 } } } > eth.accounts ["0xa86c4c8864edf91fe0be416f7e252e90ade98a60", "0x642b43d11fe2cdf725a8970b7342c530bcc363f2", "0xaf07e1acba2194de5636a65e3df84b8bfc328431", "0xe82a61eb05bd2048fc91c9065e0757f119033f75"]

testNode2节点的账户,账户密码都设置成123456

> admin.nodeInfo { enode: "enode://c539b7f91a709d9590121fbf4518ee1632d2999f1d67408c864bd2fab968376b39d1167871ccd1a2468bbdb89681404f2f2686722830897c75c13e45acc94a07@[::]:30305", id: "c539b7f91a709d9590121fbf4518ee1632d2999f1d67408c864bd2fab968376b39d1167871ccd1a2468bbdb89681404f2f2686722830897c75c13e45acc94a07", ip: "::", listenAddr: "[::]:30305", name: "Geth/testNode2/v1.8.11-stable-dea1ce05/windows-amd64/go1.10.2", ports: { discovery: 30305, listener: 30305 }, protocols: { eth: { config: { chainId: 13, eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000", eip155Block: 0, eip158Block: 0, homesteadBlock: 0 }, difficulty: 26119992, genesis: "0x9de6c673941ebfa13a4494828e24cb206556386ef81249a65e203588be457315", head: "0xccc4b409a7d29a6bf224acadf33dd9c581b3fba2b2460e2cc42b865200d0524c", network: 29382 } } } > eth.accounts ["0x4ff80c7a558f9d81912c2815390191528918f0a1", "0x1512435267caa2e09ee4b13d373efb2bf68a872e", "0xf79cf5378e8c9728fcfdc33d155186059fbf0084"]

admin.addPeer("enode://6f7d8a0caa1d40c04c8c9b9b4e0a42ac4591b815b17f2ea16d2c1e460287e8fbb81e1c96e4f739331cce0df278e3487b91e0640908b522ccf9e10892b35a708e@[192.168.0.101]:30304")

在testNode1节点启动挖矿,在testNode2节点会看到同步信息
#testNode1 miner.start(1)INFO [08-01|07:41:20] Updated mining threadsthreads=1 INFO [08-01|07:41:20] Transaction pool price threshold updated price=18000000000 nulIlN FO>[08-01|07:41:20] Starting mining operation INFO [08-01|07:41:20] Commit new mining worknumber=148 txs=0 uncles=0 elapsed=0s INFO [08-01|07:41:20]

说明节点通信成功。
打开mist v0.11.1会自动连接到testNode1主节点,testNode1节点的三个账户
Geth + mist+私有链部署智能合约-5.2
文章图片

部署合约,合约代码来自https://ethereum.org/token;从testNode1节点的testNode1_1账户向testNode1_2账户转账以太和代币,向合约转账代币,但是不能向合约转账以太,合约可以持有以太吗?
Geth + mist+私有链部署智能合约-5.2
文章图片

看以太坊网站上的其他合约都没有持有以太,合约应该是不能持有以太的。
从testNode1_1账户向testNode2_2账户发起一笔交易后输入密码进入待确认状态
mist窗口显示待确认交易
Geth + mist+私有链部署智能合约-5.2
文章图片

testNode1窗口显示待确认交易
> INFO [08-01|08:18:05] Submitted transactionfullhash=0xf5ee21b8541118427d7fff2c7f520decc9886d98577195e6297fb8d5c9b0e3b6 recipient=0x642B43d11fE2cDF725a8970b7342c530bcc363F2

miner.start(1)testNode1发起确认交易后
mist窗口开始同步确认
Geth + mist+私有链部署智能合约-5.2
文章图片

testNode1窗口开始挖矿
true > INFO [08-01|08:18:05] Submitted transactionfullhash=0xf5ee21b8541118427d7fff2c7f520decc9886d98577195e6297fb8d5c9b0e3b6 recipient=0x642B43d11fE2cDF725a8970b7342c530bcc363F2 > miner.start(1) INFO [08-01|08:20:10] Updated mining threadsthreads=1 INFO [08-01|08:20:10] Transaction pool price threshold updated price=18000000000 InNuFlOl [08- 0> 1|08:20:10] Starting mining operation INFO [08-01|08:20:10] Commit new mining worknumber=186 txs=1 uncles=0 elapsed=0s INFO [08-01|08:20:11] Successfully sealed new blocknumber=186 hash=8e3ddb…f38977 INFO [08-01|08:20:11]

testNode2同步区块
> INFO [08-01|08:12:49] Imported new chain segmentblocks=1 txs=1 mgas=0.021 elapsed=9.978msmgasps=2.104number=172 hash=bb64fd…de7f66 cache=63.33kB INFO [08-01|08:12:50] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=4.984msmgasps=0.000number=173 hash=5494f6…d91b10 cache=63.63kB INFO [08-01|08:12:53] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=6.976msmgasps=0.000number=174 hash=5a29ac…129393 cache=63.94kB INFO [08-01|08:12:55] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=12.965msmgasps=0.000number=175 hash=5d3c54…b9a549 cache=64.25kB INFO [08-01|08:12:58] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=5.985msmgasps=0.000number=176 hash=1f47ff…8b3abd cache=64.56kB INFO [08-01|08:13:02] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=24.94msmgasps=0.000number=177 hash=4b6895…ff3a27 cache=64.87kB INFO [08-01|08:13:02] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=16.974msmgasps=0.000number=178 hash=d45468…fd8c04 cache=65.18kB INFO [08-01|08:13:04] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=5.981msmgasps=0.000number=179 hash=68b564…e7ae27 cache=65.49kB INFO [08-01|08:13:14] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=8.976msmgasps=0.000number=180 hash=8a5586…feeb28 cache=65.80kB INFO [08-01|08:13:18] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=10.968msmgasps=0.000number=181 hash=93a7e5…c27eb9 cache=66.11kB INFO [08-01|08:13:18] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=8.973msmgasps=0.000number=182 hash=5e10c3…af0d42 cache=66.42kB INFO [08-01|08:13:22] Imported new chain segmentblocks=1 txs=0 mgas=0.000 elapsed=11.969msmgasps=0.000

交易完成之后挖矿还是进行,需要进一步确认这些被确认的交易是什么交易?这些交易也是最testNode1账户最初以太的来源。

    推荐阅读