{"id":1769,"date":"2023-03-25T12:09:09","date_gmt":"2023-03-25T04:09:09","guid":{"rendered":""},"modified":"2023-03-25T12:42:23","modified_gmt":"2023-03-25T04:42:23","slug":"%e4%bb%a5%e5%a4%aa%e5%9d%8aethereum-%e9%83%a8%e7%bd%b2%e6%99%ba%e8%83%bd%e5%90%88%e7%ba%a6%e5%88%b0%e5%85%ac%e9%93%be","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1769.html","title":{"rendered":"\u4ee5\u592a\u574a\u2013 \u90e8\u7f72\u667a\u80fd\u5408\u7ea6\u5230\u516c\u94fe"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

\u4ee5\u592a\u574a(Ethereum) \u2013 \u90e8\u7f72\u667a\u80fd\u5408\u7ea6\u5230\u516c\u94fe<\/h1>\n<\/p><\/div>\n
\n \u73b0\u5728\uff0c\u6211\u4eec\u5c06\u667a\u80fd\u5408\u7ea6\u90e8\u7f72\u5230\u516c\u94fe\u3002\u6b65\u9aa4\u5982\u4e0b\uff1a\n <\/div>\n

\u90e8\u7f72\u9700\u8981\u6d88\u8017Gas\uff0c\u83b7\u53d6\u6d4b\u8bd5\u4ee5\u592a\u5e01\u7528\u4e8e\u90e8\u7f72<\/span>
\n \u90e8\u7f72\u667a\u80fd\u5408\u7ea6<\/span>
\n \u9a8c\u8bc1\u90e8\u7f72<\/span> <\/p>\n

\u83b7\u53d6\u6d4b\u8bd5\u4ee5\u592a\u5e01<\/h2>\n
\n \u90e8\u7f72\u9700\u8981\u6d88\u8017Gas\uff0cGas\u9700\u8981\u652f\u4ed8\u4ee5\u592a\u5e01\uff0c\u6211\u4eec\u90e8\u7f72\u5230\u7684\u662f\u516c\u94fe\u6d4b\u8bd5\u7f51Kovan\uff0c\u7f51\u7edc\u4e2d\u7684\u4ee5\u592a\u5e01\u6ca1\u6709\u5e02\u573a\u4ef7\u503c\u3002\n <\/div>\n
\n \u53ef\u4ee5\u4eceKovan faucet Gitter\u804a\u5929\u5ba4\u83b7\u53d6\u6d4b\u8bd5\u7528\u7684\u4f2a\u4ee5\u592a\u5e01\u3002\u53ea\u9700\u628a\u94b1\u5305\u5730\u5740\u53d1\u9001\u51fa\u53bb\uff0c\u7ea65\u5206\u949f\u5185\uff0c\u6709\u4eba\u4f1a\u7ed9\u4f60\u53d1\u6d4b\u8bd5\u7528\u7684\u4f2a\u4ee5\u592a\u5e01\u3002\n <\/div>\n
\n \u6253\u5f00Ganache\u5e76\u590d\u5236\u5217\u8868\u4e2d\u7b2c\u4e00\u4e2a\u5e10\u6237\u7684\u5730\u5740(\u94b1\u5305\u5730\u5740)\uff0c\u7c7b\u4f3c\u4e0b\u9762\u6240\u793a\uff1a\n <\/div>\n
\n
0x29920e756f41F8e691aE0b12D417C19204371E91\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u53d1\u9001\u5230\u804a\u5929\u5ba4\u5185\uff0c\u7a0d\u7b49\u7247\u523b\uff0c\u4f60\u7684\u8d26\u53f7\u5c06\u6536\u5230\u4e00\u7b14\u4ee5\u592a\u5e01\u3002\n <\/div>\n

\u90e8\u7f72\u667a\u80fd\u5408\u7ea6<\/h2>\n
\n \u73b0\u5728\u5e10\u6237\u91cc\u5df2\u7ecf\u6709\u4e86\u8d44\u91d1\uff0c\u53ef\u4ee5\u8fdb\u884c\u90e8\u7f72\u4e86\u3002\n <\/div>\n
\n \u6267\u884c\u90e8\u7f72\u547d\u4ee4\uff1a\n <\/div>\n
\n
truffle migrate--network kovan\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u4e00\u65e6\u90e8\u7f72\u5b8c\u6210\uff0c\u5e94\u8be5\u4f1a\u770b\u5230\u90e8\u7f72\u6210\u529f\u7684\u6d88\u606f\u3002\n <\/div>\n
\n \u90e8\u7f72\u547d\u4ee4\u6267\u884c\u8be6\u60c5\uff1a\n <\/div>\n
\n
G:\\qikegu\\ethereum\\mydapp>truffle migrate--network kovan\r\nCompiling your contracts...\r\n===========================\r\n> Everything is up to date, there is nothing to compile.\r\nMigrations dry-run (simulation)\r\n===============================\r\n> Network name:    'kovan-fork'<\/span>\r\n> Network id:      42\r\n> Block gas limit: 0x7a1200\r\n...\r\nStarting migrations...\r\n======================\r\n> Network name:    'kovan'<\/span>\r\n> Network id:      42\r\n> Block gas limit: 0x7a1200\r\n1_initial_migration.js\r\n======================\r\n   Deploying 'Migrations'<\/span>\r\n  ----------------------\r\n   > transaction hash:    0x7e30b5c716afed45888a9dd2d6af7e6f52a9fade0346e8ad7d0c268de508a26a\r\n   > Blocks: 2            Seconds: 9\r\n   > contract address:    0x168A7247B58786edd259502948f5Bf9449C863AD\r\n   > block number:        13447029\r\n   > block timestamp:     1568294312\r\n   > account:             0x29920e756f41F8e691aE0b12D417C19204371E91\r\n   > balance:             2.993465175\r\n   > gas used:            261393\r\n   > gas price:           25 gwei\r\n   > value sent:          0 ETH\r\n   > total cost:          0.006534825 ETH\r\n   > Saving migration to chain.\r\n   > Saving artifacts\r\n  -------------------------------------\r\n   > Total cost:         0.006534825 ETH\r\n2_deploy_contracts.js\r\n=====================\r\n   Deploying 'MyContract'<\/span>\r\n  ----------------------\r\n   > transaction hash:    0xc1f7ec8fee1a23e3d08d0c9e9d6e15fef24feb8ba163e0071dccb1bb90cc0eca\r\n   > Blocks: 0            Seconds: 0\r\n   > contract address:    0x4D3CFaF8457CEA76c0409f989f9870115B4d2d82\r\n   > block number:        13447036\r\n   > block timestamp:     1568294340\r\n   > account:             0x29920e756f41F8e691aE0b12D417C19204371E91\r\n   > balance:             2.9850534\r\n   > gas used:            294448\r\n   > gas price:           25 gwei\r\n   > value sent:          0 ETH\r\n   > total cost:          0.0073612 ETH\r\n   > Saving migration to chain.\r\n   > Saving artifacts\r\n  -------------------------------------\r\n   > Total cost:           0.0073612 ETH\r\nSummary\r\n=======\r\n> Total deployments:   2\r\n> final <\/span>cost:          0.013896025 ETH\r\nSummary\r\n=======\r\n> Total deployments:   2\r\n> final <\/span>cost:          0.013896025 ETH\r\n<\/pre>\n

<\/code>\n <\/div>\n

\u9a8c\u8bc1\u90e8\u7f72<\/h2>\n
\n \u73b0\u5728\u6253\u5f00truffle\u63a7\u5236\u53f0\uff0c\u4e0ekovan\u6d4b\u8bd5\u7f51\u7edc\u4e0a\u7684\u667a\u80fd\u5408\u7ea6\u8fdb\u884c\u4ea4\u4e92:\n <\/div>\n
\n
$ truffle console--network kovan\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u5728\u63a7\u5236\u53f0\u4e2d\u6267\u884c\uff1a\n <\/div>\n
\n
truffle(kovan)> MyContract.deployed<\/span>().then<\/span>((c) => { contract = c })\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u7136\u540e\uff1a\n <\/div>\n
\n
truffle(kovan)> contract.get<\/span>()\r\n'myValue'<\/span>\r\ntruffle(kovan)> contract.set<\/span>(\"hello world\"<\/span>)\r\n{ tx:\r\n   '0x7bf63444f3a7bd70e981a7bd49228b1cf1a8c3754daf64c4c7765b8eee46bf37'<\/span><\/span>,\r\n  receipt:\r\n   { blockHash:\r\n      '0xe03d0f43d85f4e41c18a90aa563ebda08899c6b9c38d0cd7779937046e2aed0c'<\/span>,\r\n     blockNumber: 13447763,\r\n     contractAddress: null<\/span>,\r\n     cumulativeGasUsed: 33629,\r\n     from: '0x29920e756f41f8e691ae0b12d417c19204371e91'<\/span>,\r\n     gasUsed: 33629,\r\n     logs: [],\r\n     logsBloom:\r\n      '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'<\/span>,\r\n     root: null<\/span>,\r\n     status: true<\/span><\/span>,\r\n     to: '0x4d3cfaf8457cea76c0409f989f9870115b4d2d82'<\/span>,\r\n     transactionHash:\r\n      '0x7bf63444f3a7bd70e981a7bd49228b1cf1a8c3754daf64c4c7765b8eee46bf37',\r\n     transactionIndex: 0,\r\n     rawLogs: [] },\r\n  logs: [] }\r\ntruffle(kovan)> contract.get<\/span>()\r\n'hello world'<\/span>\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u53ef\u4ee5\u770b\u5230\u667a\u80fd\u5408\u7ea6\u5df2\u7ecf\u6210\u529f\u90e8\u7f72\u3002\n <\/div>\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"\u4ee5\u592a\u574a(Ethereum) \u2013 \u90e8\u7f72\u667a\u80fd\u5408\u7ea6\u5230\u516c\u94fezh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[153],"tags":[],"class_list":["post-1769","post","type-post","status-publish","format-standard","hentry","category-ytfjc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1769"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1769"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1769\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}