JobPlus知识库 IT 其它 文章
以太坊-私有链基本操作

终端运行:

@>>  geth  --datadir "./chain" --nodiscover console 2>>eth_output.log

启动geth

  1. //给自己的两个账户重命名。

  2. > user1 = eth.accounts[0]

  3. "0xfd5db5967bb4600840adde5035b8de4d56176ad5"

  4. > user2 = eth.accounts[1]

  5. "0xa740690de331a76519133175c3f28aeb865de658"

  6. //查看用户1的ETH

  7. > eth.getBalance(user1)

  8. 5.93e+21

  9. > eth.getBalance(user2)

  10. 0

  11. //解锁,转账之前必须解锁操作。

  12. > personal.unlockAccount("0xfd5db5967bb4600840adde5035b8de4d56176ad5","123456")

  13. true

  14. //将用户1给用户2转3个ETH

  15. > eth.sendTransaction({from: user1, to: user2, value: web3.toWei(3, "ether")})

  16. "0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee"

  17. //然后查看用户2的名下还是0个ETH

  18. > eth.getBalance(user2)

  19. 0

  20. //打开挖矿

  21. > miner.start()

  22. null

  23. //在转一次帐

  24. > eth.sendTransaction({from: user1, to: user2, value: web3.toWei(3, "ether")})

  25. "0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee"

  26. //查看用户2的余额 ,发现有6个ETH了。

  27. > eth.getBalance(user2)

  28. 6000000000000000000

  29. //从日志查看交易在1188号区块。

  30. INFO [07-16|17:41:03.037]

  1. //从日志查看交易在1188号区块。

  2. INFO [07-16|17:44:51.391] Submitted transaction                    fullhash=0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee recipient=0xA740690De331A76519133175c3f28aEb865De658

  3. INFO [07-16|17:45:36.188] Updated mining threads                   threads=0

  4. INFO [07-16|17:45:36.188] Transaction pool price threshold updated price=18000000000

  5. INFO [07-16|17:45:36.188] Starting mining operation

  6. INFO [07-16|17:45:36.189] Commit new mining work                   number=1188 txs=1 uncles=0 elapsed=459.147µs

  7. INFO [07-16|17:45:59.028] Updated mining threads                   threads=0

  8. INFO [07-16|17:46:02.920] Submitted transaction                    fullhash=0x976a0427817481a9a9f0c692e71151b3837ba6f3f9c4ce931df4d88d48f93b36 recipient=0xA740690De331A76519133175c3f28aEb865De658

  9. INFO [07-16|17:47:22.389] Updated mining threads                   threads=0

  10. INFO [07-16|17:47:22.389] Transaction pool price threshold updated price=18000000000

  11. INFO [07-16|17:47:22.389] Starting mining operation

  12. INFO [07-16|17:47:22.390] Commit new mining work                   number=1188 txs=2 uncles=0 elapsed=697.907µs

  13. INFO [07-16|17:47:38.532] Successfully sealed new block            number=1188 hash=83d471…e909e0

  14. INFO [07-16|17:47:38.731] Commit new mining work                   number=1189 txs=0 uncles=0 elapsed=1.320ms

  15. INFO [07-16|17:47:38.739]

  1. //查看区块结构

  2. > eth.getBlock(1188)

  3. {

  4. difficulty: 192530,

  5. extraData: "0xd68301080c846765746886676f312e3130856c696e7578",

  6. gasLimit: 4712388,

  7. gasUsed: 42000,

  8. hash: "0x83d47151ad9f1368954780a342118f6e392c81f1b06c5cf2bc02893f46e909e0",

  9. logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",

  10. miner: "0xfd5db5967bb4600840adde5035b8de4d56176ad5",

  11. mixHash: "0xf6b8495978cb363dac64c2d81b7a34e1f470428ccc01d0dce3f31250e60b92bb",

  12. nonce: "0x7cd563b32336f4cb",

  13. number: 1188,

  14. parentHash: "0xbd8f131597c2b7d2aaba79d41cb86ac49bbaa127a457983e54542a680500de85",

  15. receiptsRoot: "0x7630e5ee1973f3546582909785a1ee5d9bf862187e1df48cfc6fe64bd634a0fe",

  16. sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",

  17. size: 761,

  18. stateRoot: "0x44880a00af0e7147e651a01c0a1c3d9f07b25c276b564c1e2dad61599b0eb374",

  19. timestamp: 1531734442,

  20. totalDifficulty: 199934928,

  21. transactions: ["0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee", "0x976a0427817481a9a9f0c692e71151b3837ba6f3f9c4ce931df4d88d48f93b36"],

  22. transactionsRoot: "0x8f225fd18cfa1aefc423adc7adb985a8c5f8782378e09737b993698021caef6d",

  23. uncles: []

  24. }

  1. //查看交易记录

  2. > eth.getTransaction("0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee")

  3. {

  4. blockHash: "0x83d47151ad9f1368954780a342118f6e392c81f1b06c5cf2bc02893f46e909e0",

  5. blockNumber: 1188,

  6. from: "0xfd5db5967bb4600840adde5035b8de4d56176ad5",

  7. gas: 90000,

  8. gasPrice: 18000000000,

  9. hash: "0xf9c613bf8dadc0b18574ab019add49e9d75f9fd33fbac0fb9cb8f50266d0cbee",

  10. input: "0x",

  11. nonce: 0,

  12. r: "0x37c724075bd5c79c629f5ef09209ed1e9b01c4cc5410249c52b6dd7d33f33894",

  13. s: "0x47497db5fec98dfec5b0a9e04a6f8a74d26b6f92d3163010ec1d07e5b640a818",

  14. to: "0xa740690de331a76519133175c3f28aeb865de658",

  15. transactionIndex: 0,

  16. v: "0x2a",

  17. value: 3000000000000000000

  18. }


如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

¥ 打赏支持
449人赞 举报
分享到
用户评价(0)

暂无评价,你也可以发布评价哦:)

扫码APP

扫描使用APP

扫码使用

扫描使用小程序