{"id":2542,"date":"2024-08-10T11:30:00","date_gmt":"2024-08-10T03:30:00","guid":{"rendered":"https:\/\/systw.net\/note\/?p=2542"},"modified":"2025-12-07T17:09:28","modified_gmt":"2025-12-07T09:09:28","slug":"solidity%e9%81%8b%e4%bd%9c%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/systw.net\/note\/archives\/2542","title":{"rendered":"Solidity and Remix"},"content":{"rendered":"\n<p>Solidity \u7684\u904b\u4f5c\u65b9\u5f0f\u53ef\u4ee5\u5206\u89e3\u70ba\u4e09\u500b\u4e3b\u8981\u6b65\u9a5f\uff1a\u7de8\u5beb\u3001\u7de8\u8b6f \u548c \u57f7\u884c\u3002\u958b\u767c\u8005\u80fd\u7528\u4eba\u985e\u80fd\u61c2\u7684\u8a9e\u8a00\u5beb\u7a0b\u5f0f\uff0c\u7136\u5f8c\u7de8\u8b6f\u5668\u5c07\u5176\u7ffb\u8b6f\u6210\u6a5f\u5668\u8a9e\u8a00\uff0c\u6700\u7d42\u7531\u5404\u7bc0\u9ede\u5728\u53bb\u4e2d\u5fc3\u5316\u7684\u74b0\u5883\u4e2d\u57f7\u884c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u7de8\u5beb (Writing)<\/h3>\n\n\n\n<p>\u9996\u5148\uff0c\u958b\u767c\u8005\u4f7f\u7528 Solidity \u8a9e\u8a00\u4f86\u7de8\u5beb\u667a\u80fd\u5408\u7d04\u3002\u9019\u6bb5\u7a0b\u5f0f\u78bc\u5305\u542b\u4e86\u5408\u7d04\u7684\u908f\u8f2f\u3001\u898f\u5247\u548c\u8b8a\u6578\uff0c\u4f8b\u5982\u4e00\u500b\u4ee3\u5e63\u5408\u7d04\u5982\u4f55\u8655\u7406\u8f49\u5e33\u3001\u6216\u4e00\u500b\u62cd\u8ce3\u5408\u7d04\u5982\u4f55\u7ba1\u7406\u51fa\u50f9\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u7de8\u8b6f (Compiling)<\/h3>\n\n\n\n<p>\u5beb\u597d\u7684 Solidity \u7a0b\u5f0f\u78bc\u662f\u4eba\u985e\u53ef\u8b80\u7684\uff0c\u4f46\u5340\u584a\u93c8\u7684\u5e95\u5c64\u865b\u64ec\u6a5f\uff08\u4f8b\u5982 EVM\uff0c\u4ee5\u592a\u574a\u865b\u64ec\u6a5f\uff09\u7121\u6cd5\u76f4\u63a5\u7406\u89e3\u3002\u56e0\u6b64\uff0c\u6211\u5011\u9700\u8981\u4f7f\u7528\u4e00\u500b\u7a31\u70ba Solidity \u7de8\u8b6f\u5668 (solc) \u7684\u5de5\u5177\uff0c\u5c07\u7a0b\u5f0f\u78bc\u8f49\u63db\u6210 EVM \u80fd\u5920\u57f7\u884c\u7684 \u4f4d\u5143\u78bc (bytecode)\u3002<\/p>\n\n\n\n<p>\u9019\u500b\u4f4d\u5143\u78bc\u662f\u5408\u7d04\u7684\u6a5f\u5668\u8a9e\u8a00\uff0c\u7531\u4e00\u7cfb\u5217\u4f4e\u968e\u7684\u6307\u4ee4\uff08\u7a31\u70ba opcode\uff09\u7d44\u6210\u3002\u7de8\u8b6f\u904e\u7a0b\u9084\u6703\u7522\u751f ABI (Application Binary Interface)\uff0c\u5b83\u5c31\u50cf\u662f\u5408\u7d04\u7684\u516c\u958b\u4ecb\u9762\u8aaa\u660e\u66f8\uff0c\u544a\u8a34\u5916\u754c\u5982\u4f55\u8207\u5408\u7d04\u4e92\u52d5\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u57f7\u884c (Executing)<\/h3>\n\n\n\n<p>\u4e00\u65e6\u5408\u7d04\u88ab\u7de8\u8b6f\u6210\u4f4d\u5143\u78bc\uff0c\u5b83\u5c31\u53ef\u4ee5\u88ab\u90e8\u7f72\u5230\u5340\u584a\u93c8\u4e0a\u3002\u7576\u7528\u6236\u8207\u5408\u7d04\u4e92\u52d5\uff08\u4f8b\u5982\u547c\u53eb\u4e00\u500b\u51fd\u5f0f\uff09\u6642\uff0c\u9019\u500b\u904e\u7a0b\u6703\u5728\u6240\u6709\u904b\u884c\u5340\u584a\u93c8\u7db2\u8def\u7684\u7bc0\u9ede\u4e0a\u767c\u751f\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4ea4\u6613 (Transaction)\uff1a\u5982\u679c\u4e92\u52d5\u6703\u6539\u8b8a\u5340\u584a\u93c8\u7684\u72c0\u614b\uff08\u4f8b\u5982\u767c\u9001\u4ee3\u5e63\uff09\uff0c\u90a3\u9ebc\u9019\u6703\u662f\u4e00\u500b\u4ea4\u6613\u3002\u9019\u7b46\u4ea4\u6613\u6703\u88ab\u767c\u9001\u5230\u7db2\u8def\u4e0a\uff0c\u7531\u7926\u5de5\u6216\u9a57\u8b49\u8005\u6253\u5305\u5230\u5340\u584a\u4e2d\u3002<\/li>\n\n\n\n<li>\u7bc0\u9ede\u904b\u7b97\uff1a\u6bcf\u500b\u7bc0\u9ede\u7684\u5e95\u5c64\u865b\u64ec\u6a5f\u90fd\u6703\u8f09\u5165\u5408\u7d04\u7684\u4f4d\u5143\u78bc\uff0c\u4e26\u57f7\u884c\u5176\u4e2d\u7684\u6307\u4ee4\u3002\u7bc0\u9edeEVM \u6703\u8ffd\u8e64\u6240\u6709\u7684\u72c0\u614b\u8b8a\u52d5\uff0c\u4e26\u78ba\u4fdd\u6bcf\u500b\u7bc0\u9ede\u90fd\u5f97\u5230\u76f8\u540c\u7684\u7d50\u679c\u3002\u9019\u5c31\u662f\u5340\u584a\u93c8\u9054\u6210\u5171\u8b58\u7684\u95dc\u9375\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Solidity\u7bc4\u4f8b<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u662fSolidity\u53ef\u986f\u793aHello World\u7684\u7bc4\u4f8b\u7a0b\u5f0f\u78bc<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract HelloWorld {\n    string public message;\n\n    constructor() {\n        message = \"Hello World\";\n    }\n\n    function updateMessage(string memory _newMessage) public {\n        message = _newMessage;\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u7a0b\u5f0f\u78bc\u89e3\u8aaa<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong><code>pragma solidity ^0.8.20;<\/code><\/strong>: \u6307\u5b9a\u7de8\u8b6f\u5668\u7248\u672c\u3002\u9019\u884c\u544a\u8a34\u7de8\u8b6f\u5668\uff0c\u9019\u500b\u5408\u7d04\u9700\u8981\u4f7f\u7528 <code>0.8.20<\/code> \u6216\u66f4\u65b0\uff0c\u4f46\u4e0d\u9ad8\u65bc <code>0.9.0<\/code> \u7684 Solidity \u7248\u672c\u4f86\u7de8\u8b6f\u3002<\/li>\n\n\n\n<li><strong><code>contract HelloWorld { ... }<\/code><\/strong>: \u9019\u662f\u5b9a\u7fa9\u4e00\u500b\u667a\u80fd\u5408\u7d04\u7684\u95dc\u9375\u5b57\u3002<code>HelloWorld<\/code> \u662f\u9019\u500b\u5408\u7d04\u7684\u540d\u7a31\u3002<\/li>\n\n\n\n<li><strong><code>string public message;<\/code><\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>string<\/code> \u662f\u4e00\u7a2e\u7528\u65bc\u5132\u5b58\u6587\u5b57\u7684\u8b8a\u6578\u985e\u578b\u3002<\/li>\n\n\n\n<li><code>public<\/code> \u95dc\u9375\u5b57\u5f88\u7279\u5225\u3002\u7576\u4f60\u5c07\u4e00\u500b\u72c0\u614b\u8b8a\u6578\u8a2d\u70ba <code>public<\/code> \u6642\uff0cSolidity \u6703\u81ea\u52d5\u70ba\u4f60\u5275\u5efa\u4e00\u500b\u540c\u540d\u7684 <code>getter<\/code> \u51fd\u5f0f\u3002\u9019\u610f\u5473\u8457\uff0c\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u900f\u904e\u547c\u53eb <code>message()<\/code> \u9019\u500b\u51fd\u5f0f\u4f86\u8b80\u53d6 <code>message<\/code> \u8b8a\u6578\u7684\u503c\uff0c\u800c\u4e0d\u9700\u8981\u6211\u5011\u81ea\u5df1\u624b\u52d5\u5beb\u4e00\u500b <code>getMessage<\/code> \u7684\u51fd\u5f0f\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>constructor() { ... }<\/code><\/strong>: <strong>\u5efa\u69cb\u51fd\u5f0f<\/strong>\uff0c\u53ea\u5728\u5408\u7d04\u90e8\u7f72\u5230\u5340\u584a\u93c8\u6642\u57f7\u884c\u4e00\u6b21\u3002\u5728\u9019\u88e1\uff0c\u6211\u5011\u5c07 <code>message<\/code> \u7684\u521d\u59cb\u503c\u8a2d\u5b9a\u70ba <code>\"Hello World\"<\/code>\u3002<\/li>\n\n\n\n<li><strong><code>function updateMessage(string memory _newMessage) public { ... }<\/code><\/strong>:\n<ul class=\"wp-block-list\">\n<li><code>updateMessage<\/code> \u662f\u4e00\u500b\u516c\u5171\u51fd\u5f0f\uff0c\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u547c\u53eb\u5b83\u3002<\/li>\n\n\n\n<li>\u5b83\u63a5\u53d7\u4e00\u500b\u540d\u70ba <code>_newMessage<\/code> \u7684\u53c3\u6578\uff0c\u985e\u578b\u662f <code>string memory<\/code>\u3002<code>memory<\/code> \u8868\u793a\u9019\u500b\u5b57\u4e32\u662f\u5132\u5b58\u5728\u8a18\u61b6\u9ad4\u4e2d\uff0c\u53ea\u5728\u51fd\u5f0f\u57f7\u884c\u671f\u9593\u5b58\u5728\u3002<\/li>\n\n\n\n<li>\u51fd\u5f0f\u5167\u90e8\uff0c\u6211\u5011\u5c07 <code>message<\/code> \u7684\u503c\u66f4\u65b0\u70ba\u50b3\u5165\u7684 <code>_newMessage<\/code>\u3002\u7531\u65bc\u9019\u6703\u6539\u8b8a\u5340\u584a\u93c8\u7684\u72c0\u614b\uff0c\u56e0\u6b64\u57f7\u884c\u9019\u500b\u51fd\u5f0f\u9700\u8981\u82b1\u8cbb Gas\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Remix IDE<\/h2>\n\n\n\n<p>Remix IDE (Integrated Development Environment\uff0c\u6574\u5408\u5f0f\u958b\u767c\u74b0\u5883) \u662f\u4e00\u500b\u5c08\u70ba\u958b\u767c\u3001\u6e2c\u8a66\u548c\u90e8\u7f72\u667a\u80fd\u5408\u7d04 (Smart Contracts) \u800c\u8a2d\u8a08\u7684\u5f37\u5927\u958b\u6e90\u5de5\u5177\u3002\u5b83\u6700\u4e3b\u8981\u7684\u512a\u9ede\u662f\u57fa\u65bc\u7db2\u9801\uff0c\u4f60\u4e0d\u9700\u8981\u5b89\u88dd\u4efb\u4f55\u6771\u897f\uff0c\u53ea\u9700\u8981\u4e00\u500b\u700f\u89bd\u5668\u5c31\u80fd\u958b\u59cb\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u5c07\u4e0a\u8ff0\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\u8cbc\u5230 Remix IDE\uff08\u4e00\u500b\u7dda\u4e0a\u958b\u767c\u74b0\u5883\uff09\u4e2d\uff0c\u7136\u5f8c\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>\u9ede\u64ca\u5de6\u5074\u7684\u300c<code>Compile<\/code>\u300d\u6a19\u7c64\uff0c\u7de8\u8b6f\u5408\u7d04\u3002<\/li>\n\n\n\n<li>\u5207\u63db\u5230\u300c<code>Deploy &amp; Run Transactions<\/code>\u300d\u6a19\u7c64\uff0c\u90e8\u7f72\u5408\u7d04\u3002\n<ul class=\"wp-block-list\">\n<li>ENVIRONMENT\u9078Remix VM\uff0c\u4efb\u4e00\u500b\u90fd\u53ef\u4ee5<\/li>\n\n\n\n<li>ACCOUNT\u9078\u4efb\u4f55\u4e00\u500b\u90fd\u53ef\u4ee5<\/li>\n\n\n\n<li>\u4f48\u7f72\u5b8c\u5f8c\u6703\u51fa\u73fe\u8a0a\u606f\uff0c\u4f8b\u5982<code>[vm]from: 0x5B3...eddC4to: HelloWorld.(constructor)value: 0 weidata: 0x608...e0033logs: 0hash: 0xcc6...0ac72<\/code><\/li>\n\n\n\n<li>\u5c55\u958b\u8a0a\u606f\u6703\u770b\u5230contract address\uff0c\u4f8b\u5982<code>0x7EF2e0048f5bAeDe046f6BF797943daF4ED8CB47<\/code><a href=\"https:\/\/remix.ethereum.org\/#\" target=\"_blank\" rel=\"noopener\"><\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u90e8\u7f72\u5b8c\u6210\u5f8c\uff0c\u5728<code>Deployed Contracts<\/code>\u4e0b\u65b9\u770b\u5230\u5408\u7d04\u7684\u4ecb\u9762\u3002\n<ul class=\"wp-block-list\">\n<li>\u6bcf\u6b21\u4f48\u7f72\u90fd\u6703\u7522\u751f\u65b0\u7684contract address\uff0c\u5982\u679c\u4f48\u7f72\u591a\u6b21\u6703\u51fa\u73fe\u591a\u500b\uff0c\u9078\u64c7\u5176\u4e2d\u4e00\u500b\u4f48\u7f72\u7684\u5408\u7d04\u5730\u5740\u5373\u53ef<\/li>\n\n\n\n<li>\u5982\u679c\u4e0d\u5c0f\u5fc3\u522a\u9664\u6216\u91cd\u958b\u5f8c\u6d88\u5931\uff0c\u53ef\u5728\u4e0a\u65b9\u7684<code>At Address<\/code>\u8f38\u5165\u4e4b\u524d\u4f48\u7f72\u7684\u5408\u7d04\u4f4d\u7f6e\u6309\u4e0b\u5f8c\uff0c\u5c31\u6703\u5728\u51fa\u73fe<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5c55\u958b\u5408\u7d04\uff0c\u4e0b\u65b9\u6703\u51fa\u73fe\u4e00\u500b\u65b0\u7684\u5340\u584a\uff0c\u986f\u793a\u4f60\u5408\u7d04\u4e2d\u7684\u6240\u6709 <code>public<\/code> \u548c <code>external<\/code> \u51fd\u5f0f\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u7d05\u8272\u6309\u9215\uff1a<\/strong> \u4ee3\u8868\u9019\u500b\u51fd\u5f0f\u6703 <strong>\u4fee\u6539<\/strong> \u5340\u584a\u93c8\u7684\u72c0\u614b (\u9700\u8981\u82b1\u8cbb Gas)\u3002<\/li>\n\n\n\n<li><strong>\u85cd\u8272\u6309\u9215\uff1a<\/strong> \u4ee3\u8868\u9019\u500b\u51fd\u5f0f\u53ea\u6703 <strong>\u8b80\u53d6<\/strong> \u5340\u584a\u93c8\u7684\u72c0\u614b (\u4e0d\u9700\u8981\u82b1\u8cbb Gas)\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u85cd\u8272\u6309\u9215\u6e2c\u8a66\uff0c\u53ef\u9ede\u64ca <code>message<\/code> \u6309\u9215\u5c31\u6703\u51fa\u73fe <code>0:string: Hello World<\/code>\u3002<\/li>\n\n\n\n<li>\u7d05\u8272\u6309\u9215\u6e2c\u8a66\uff0c\u53ef\u5728 <code>updateMessage<\/code> \u51fd\u5f0f\u65c1\u7684\u8f38\u5165\u6846\u4e2d\uff0c\u8f38\u5165\u60f3\u66f4\u6539\u7684\u65b0\u8a0a\u606f\uff08\u4f8b\u5982 <code>\"Hello Blockchain\"<\/code>\uff09\uff0c\u7136\u5f8c\u9ede\u64ca <code>updateMessage<\/code> \u6309\u9215\u3002\u53ef\u4ee5\u6ce8\u610f\u5230\u8a0a\u606f\u63d0\u5230\u82b1\u8cbb\u4e8632263 gas <\/li>\n\n\n\n<li>\u518d\u6b21\u9ede\u64ca <code>message<\/code> \u6309\u9215\u5c31\u6703\u51fa\u73fe<code>0:string: Hello Blockchain<\/code>\uff0c\u6703\u767c\u73fe\u8a0a\u606f\u5df2\u7d93\u88ab\u6210\u529f\u66f4\u65b0\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Environment (\u74b0\u5883)<\/strong><\/h4>\n\n\n\n<p>\u5728 Remix IDE\u7684<code>Deploy &amp; Run Transactions<\/code>\u4e2d\uff0cEnvironment\u53ef\u6307\u5b9a\u5728\u54ea\u500b\u5340\u584a\u93c8\u74b0\u5883\u4e2d\u57f7\u884c\u4f60\u7684\u5408\u7d04\uff0c\u6c7a\u5b9a\u4e86\u4f60\u7684\u5408\u7d04\u6703\u90e8\u7f72\u5230\u54ea\u88e1\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>Remix VM<\/code><\/strong> (Remix \u865b\u64ec\u6a5f)\uff1a\u9019\u662f Remix \u5167\u5efa\u7684\u6a21\u64ec\u5340\u584a\u93c8\u74b0\u5883\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u512a\u9ede\uff1a<\/strong> \u5340\u584a\u93c8\u7684\u904b\u4f5c\u901f\u5ea6\u975e\u5e38\u5feb\uff0c\u4e0d\u9700\u8981\u9023\u63a5\u5230\u4efb\u4f55\u5916\u90e8\u7db2\u8def\uff0c\u6240\u6709\u4ea4\u6613\u90fd\u662f\u5373\u6642\u7684\u3002\u4f60\u53ef\u4ee5\u514d\u8cbb\u6e2c\u8a66\u5408\u7d04\uff0c\u4e0d\u9700\u8981\u82b1\u8cbb\u4efb\u4f55 Gas\u3002<\/li>\n\n\n\n<li><strong>\u7f3a\u9ede\uff1a<\/strong> \u4ea4\u6613\u8a18\u9304\u53ea\u5b58\u5728\u65bc\u700f\u89bd\u5668\u4e2d\uff0c\u5237\u65b0\u9801\u9762\u5f8c\u6703\u6d88\u5931\u3002\u9019\u662f\u4e00\u500b\u9694\u96e2\u7684\u6c99\u76d2\u74b0\u5883\uff0c\u4e0d\u5177\u5099\u771f\u5be6\u7684\u5340\u584a\u93c8\u529f\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>Injected Provider<\/code><\/strong>\uff1a\u9019\u500b\u9078\u9805\u6703\u9023\u63a5\u4f60\u700f\u89bd\u5668\u4e2d\u7684\u9322\u5305\u64f4\u5145\u7a0b\u5f0f\uff0c\u4f8b\u5982 <strong>MetaMask<\/strong>\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u512a\u9ede\uff1a<\/strong> \u8b93\u4f60\u53ef\u4ee5\u5728\u771f\u5be6\u7684\u5340\u584a\u93c8\u7db2\u8def\uff08\u5982\u4e3b\u7db2\u3001\u6e2c\u8a66\u7db2\u6216\u672c\u5730\u7db2\u8def\uff09\u4e0a\u90e8\u7f72\u548c\u4e92\u52d5\u5408\u7d04\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4f60\u7684\u771f\u5be6\u5e33\u6236\u4e26\u82b1\u8cbb\u771f\u5be6\u7684 Gas\u3002<\/li>\n\n\n\n<li><strong>\u7f3a\u9ede\uff1a<\/strong> \u9700\u8981\u9023\u63a5\u5230\u7db2\u8def\uff0c\u4ea4\u6613\u9700\u8981\u7b49\u5f85\u5340\u584a\u78ba\u8a8d\u6642\u9593\uff0c\u4e26\u4e14\u6703\u6d88\u8017\u771f\u5be6\u7684 Gas\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>Hardhat Provider<\/code><\/strong>  \uff1a\u9019\u9078\u9805\u8b93\u4f60\u9023\u63a5\u5230\u672c\u5730\u7aef\u904b\u884c\u7684\u958b\u767c\u74b0\u5883\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u512a\u9ede\uff1a<\/strong> \u63d0\u4f9b\u4e86\u66f4\u5f37\u5927\u7684\u958b\u767c\u548c\u6e2c\u8a66\u529f\u80fd\uff0c\u9069\u5408\u9032\u968e\u958b\u767c\u8005\u3002<\/li>\n\n\n\n<li><strong>\u7f3a\u9ede\uff1a<\/strong> \u9700\u8981\u984d\u5916\u8a2d\u5b9a\u672c\u5730\u958b\u767c\u74b0\u5883\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Account (\u5e33\u6236)<\/strong><\/h4>\n\n\n\n<p>\u5728 Remix IDE\u7684<code>Deploy &amp; Run Transactions<\/code>\u4e2d\uff0cAccount\u7528\u4f86\u9078\u64c7\u4e00\u500b\u5e33\u6236\u4f86\u90e8\u7f72\u6216\u57f7\u884c\u4ea4\u6613\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>Remix VM<\/code> \uff1a<\/strong> \u9019\u88e1\u6703\u9810\u8a2d\u63d0\u4f9b\u5e7e\u500b\u5e36\u6709\u865b\u64ec\u8cc7\u91d1\u7684\u6e2c\u8a66\u5e33\u6236\uff0c\u4f60\u53ef\u4ee5\u4efb\u610f\u9078\u64c7\u4e00\u500b\u4f86\u4f7f\u7528\uff0c\u4e0d\u7528\u64d4\u5fc3\u82b1\u8cbb\u3002<\/li>\n\n\n\n<li><strong><code>Injected Provider<\/code> \uff1a<\/strong> \u9019\u500b\u5217\u8868\u6703\u986f\u793a\u4f60\u9023\u63a5\u7684 MetaMask \u9322\u5305\u4e2d\u6240\u6709\u53ef\u7528\u7684\u5e33\u6236\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">ABI<\/h2>\n\n\n\n<p>ABI (Application Binary Interface)\u5c31\u50cf\u662f\u5408\u7d04\u7684\u300c\u8aaa\u660e\u66f8\u300d\uff0c\u7528\u4f86\u5b9a\u7fa9\u5408\u7d04\u4e2d\u6240\u6709\u51fd\u5f0f\u7684\u516c\u958b\u4ecb\u9762\u3002\u6709\u4e86\u9019\u500b ABI\uff0c\u5916\u90e8\u61c9\u7528\u7a0b\u5f0f\uff08\u5982 Remix IDE\u3001MetaMask \u9322\u5305\u6216\u4efb\u4f55 dApp\uff09\u624d\u80fd\u77e5\u9053\u5982\u4f55\u8207\u4f60\u7684\u667a\u80fd\u5408\u7d04\u4e92\u52d5\u3002<\/p>\n\n\n\n<p>Remix\u7684Compile\u9801\u9762\u4e0b\u65b9\u53ef\u4ee5\u7522\u751fABI\uff0c\u5206\u5340\u8aaa\u660e\u5982\u4e0b<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. \u5efa\u69cb\u51fd\u5f0f (Constructor)<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"inputs\": &#91;],\n  \"stateMutability\": \"nonpayable\",\n  \"type\": \"constructor\"\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>type: \"constructor\"<\/code><\/strong>\uff1a\u9019\u90e8\u5206\u8aaa\u660e\u4e86\u9019\u662f\u4e00\u500b\u5efa\u69cb\u51fd\u5f0f\uff0c\u53ea\u5728\u5408\u7d04\u90e8\u7f72\u6642\u57f7\u884c\u4e00\u6b21\u3002<\/li>\n\n\n\n<li><strong><code>inputs: []<\/code><\/strong>\uff1a\u7a7a\u7684\u9663\u5217\u8868\u793a\u9019\u500b\u5efa\u69cb\u51fd\u5f0f\u4e0d\u63a5\u53d7\u4efb\u4f55\u53c3\u6578\u3002<\/li>\n\n\n\n<li><strong><code>stateMutability: \"nonpayable\"<\/code><\/strong>\uff1a\u8868\u793a\u9019\u500b\u51fd\u5f0f\u6703\u4fee\u6539\u5340\u584a\u93c8\u7684\u72c0\u614b\uff08\u4f8b\u5982\u8a2d\u5b9a\u521d\u59cb\u8a0a\u606f\uff09\uff0c\u56e0\u6b64\u9700\u8981\u652f\u4ed8 Gas \u8cbb\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. <code>updateMessage<\/code> \u51fd\u5f0f<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"inputs\": &#91;\n    {\n      \"internalType\": \"string\",\n      \"name\": \"_newMessage\",\n      \"type\": \"string\"\n    }\n  ],\n  \"name\": \"updateMessage\",\n  \"outputs\": &#91;],\n  \"stateMutability\": \"nonpayable\",\n  \"type\": \"function\"\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>type: \"function\"<\/code><\/strong>\uff1a\u9019\u662f\u4e00\u500b\u666e\u901a\u7684\u51fd\u5f0f\u3002<\/li>\n\n\n\n<li><strong><code>name: \"updateMessage\"<\/code><\/strong>\uff1a\u51fd\u5f0f\u7684\u540d\u7a31\u3002<\/li>\n\n\n\n<li><strong><code>inputs<\/code><\/strong>\uff1a\u9019\u500b\u51fd\u5f0f\u63a5\u53d7\u4e00\u500b\u53c3\u6578\uff1a\n<ul class=\"wp-block-list\">\n<li><strong><code>name: \"_newMessage\"<\/code><\/strong>\uff1a\u53c3\u6578\u7684\u540d\u7a31\u3002<\/li>\n\n\n\n<li><strong><code>type: \"string\"<\/code><\/strong>\uff1a\u53c3\u6578\u7684\u985e\u578b\u662f\u5b57\u4e32\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>outputs: []<\/code><\/strong>\uff1a\u7a7a\u7684\u9663\u5217\u8868\u793a\u9019\u500b\u51fd\u5f0f\u4e0d\u56de\u50b3\u4efb\u4f55\u503c\u3002<\/li>\n\n\n\n<li><strong><code>stateMutability: \"nonpayable\"<\/code><\/strong>\uff1a\u8868\u793a\u9019\u500b\u51fd\u5f0f\u6703\u4fee\u6539\u5340\u584a\u93c8\u7684\u72c0\u614b\uff08\u66f4\u65b0\u8a0a\u606f\uff09\uff0c\u56e0\u6b64\u9700\u8981\u652f\u4ed8 Gas \u8cbb\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. <code>message<\/code> \u51fd\u5f0f<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"inputs\": &#91;],\n  \"name\": \"message\",\n  \"outputs\": &#91;\n    {\n      \"internalType\": \"string\",\n      \"name\": \"\",\n      \"type\": \"string\"\n    }\n  ],\n  \"stateMutability\": \"view\",\n  \"type\": \"function\"\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>type: \"function\"<\/code><\/strong>\uff1a\u9019\u662f\u4e00\u500b\u666e\u901a\u7684\u51fd\u5f0f\u3002<\/li>\n\n\n\n<li><strong><code>name: \"message\"<\/code><\/strong>\uff1a\u51fd\u5f0f\u7684\u540d\u7a31\u3002<\/li>\n\n\n\n<li><strong><code>inputs: []<\/code><\/strong>\uff1a\u7a7a\u7684\u9663\u5217\u8868\u793a\u9019\u500b\u51fd\u5f0f\u4e0d\u63a5\u53d7\u4efb\u4f55\u53c3\u6578\u3002<\/li>\n\n\n\n<li><strong><code>outputs<\/code><\/strong>\uff1a\u9019\u500b\u51fd\u5f0f\u6709\u4e00\u500b\u56de\u50b3\u503c\uff1a\n<ul class=\"wp-block-list\">\n<li><strong><code>type: \"string\"<\/code><\/strong>\uff1a\u56de\u50b3\u503c\u7684\u985e\u578b\u662f\u5b57\u4e32\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong><code>stateMutability: \"view\"<\/code><\/strong>\uff1a\u9019\u662f\u6700\u91cd\u8981\u7684\u90e8\u5206\u3002\u5b83\u8868\u660e\u9019\u500b\u51fd\u5f0f\u662f\u4e00\u500b <strong>\u53ea\u8b80\u51fd\u5f0f<\/strong>\uff0c\u5b83\u4e0d\u6703\u4fee\u6539\u5340\u584a\u93c8\u7684\u72c0\u614b\u3002\u56e0\u6b64\uff0c\u547c\u53eb\u9019\u500b\u51fd\u5f0f\u662f <strong>\u514d\u8cbb\u7684<\/strong>\uff0c\u4e0d\u9700\u8981\u652f\u4ed8 Gas \u8cbb\u7528\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Solidity \u7684\u904b\u4f5c\u65b9\u5f0f\u53ef\u4ee5\u5206\u89e3\u70ba\u4e09\u500b\u4e3b\u8981\u6b65\u9a5f\uff1a\u7de8\u5beb\u3001\u7de8\u8b6f \u548c \u57f7\u884c\u3002\u958b\u767c\u8005\u80fd\u7528\u4eba\u985e\u80fd\u61c2\u7684\u8a9e\u8a00\u5beb\u7a0b\u5f0f\uff0c\u7136\u5f8c\u7de8\u8b6f\u5668\u5c07\u5176\u7ffb\u8b6f\u6210\u6a5f\u5668\u8a9e\u8a00\uff0c\u6700\u7d42\u7531\u5404\u7bc0\u9ede\u5728\u53bb\u4e2d\u5fc3\u5316\u7684\u74b0\u5883\u4e2d\u57f7\u884c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[373],"tags":[],"class_list":["post-2542","post","type-post","status-publish","format-standard","hentry","category-smart-contract-develop"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/2542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/comments?post=2542"}],"version-history":[{"count":7,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/2542\/revisions"}],"predecessor-version":[{"id":2913,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/2542\/revisions\/2913"}],"wp:attachment":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/media?parent=2542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/categories?post=2542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/tags?post=2542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}