{ "version": "https://jsonfeed.org/version/1", "title": "Solidity", "description": "Solidity is an object-oriented, high-level language for implementing smart contracts. Solidity \u662f\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u3001\u7528\u4e8e\u5b9e\u73b0\u667a\u80fd\u5408\u7ea6\u7684\u9ad8\u7ea7\u8bed\u8a00\u3002", "home_page_url": "go/solidity", "feed_url": "feed/solidity.json", "icon": "https://cdn.v2ex.com/navatar/e193/47e1/1115_large.png?m=1727245122", "favicon": "https://cdn.v2ex.com/navatar/e193/47e1/1115_normal.png?m=1727245122", "items": [ { "author": { "url": "member/xinhaiw", "name": "xinhaiw", "avatar": "https://cdn.v2ex.com/gravatar/adde29af11b5d18324099ebe1f73043a?s=73&d=retro" }, "url": "t/1142423", "date_modified": "2025-07-02T02:21:39+00:00", "content_html": "

renounced \u7684\u5408\u7ea6\uff0ctax wallet \u8fd8\u662f\u53ef\u4ee5\u6539 tax \u5417

\n

https://etherscan.io/address/0xe01bc45AE62926EC4484D5d803e360931810C4F0#code

\n", "date_published": "2025-07-02T02:21:17+00:00", "title": "renounced \u7684\u5408\u7ea6\u53ef\u4ee5\u6539 tax \u5417", "id": "t/1142423" }, { "author": { "url": "member/Leo876", "name": "Leo876", "avatar": "https://cdn.v2ex.com/avatar/770e/18bd/667259_large.png?m=1711434128" }, "url": "t/1020705", "title": "\u7ebf\u4e0b | \u5168\u804c | \u5e7f\u5dde | 8k-12k | Solidity \u5f00\u53d1\u5de5\u7a0b\u5e08", "id": "t/1020705", "date_published": "2024-03-05T03:09:54+00:00", "content_html": "

\u4f60\u53ef\u4ee5\u83b7\u5f97\u7684\uff1a

\n
    \n
  1. \u5e74\u5e95\u516c\u53f8\u5229\u6da6\u5206\u7ea2\uff0c\u6839\u636e\u80fd\u529b\u62ff\u5956\u91d1
  2. \n
  3. \u524d\u6cbf\u7684\u884c\u4e1a\u8ba4\u77e5\u4e0e\u5b9d\u8d35\u7684\u521b\u4e1a\u7ecf\u5386
  4. \n
\n

\u9009\u62e9\u5927\u4e8e\u52aa\u529b\uff0c\u60f3\u5f2f\u9053\u8d85\u8f66\u3001\u8d85\u8d8a\u540c\u9f84\u4eba\u7684\u5c0f\u4f19\u4f34\u8bf7\u8ddf\u4e0a

\n

\u5c97\u4f4d\u804c\u8d23\uff1a

\n
    \n
  1. \u4ee5\u592a\u574a\u667a\u80fd\u5408\u7ea6\u5f00\u53d1\u3002
  2. \n
  3. \u7814\u7a76\u533a\u5757\u94fe\u9886\u57df\u667a\u80fd\u5408\u7ea6\u7b97\u6cd5\uff0c\u68b3\u7406\u4e3b\u6d41\u516c\u94fe\u5e73\u53f0\u7684\u667a\u80fd\u5408\u7ea6\u6280\u672f\u73b0\u72b6\u4e0e\u4f18\u52a3\u3002\u5bf9\u89c4\u8303\u7684\u667a\u80fd\u5408\u7ea6\u4f53\u7cfb\u6df1\u5165\u7814\u7a76\uff0c\u5305\u62ec\u4e0d\u9650\u4e8e\u4ee5\u592a\u574a\u7b49\u667a\u80fd\u5408\u7ea6\u865a\u62df\u673a\u548c\u7f16\u7a0b\u8bed\u8a00\u3001\u89c4\u8303\u3002
  4. \n
  5. \u6839\u636e\u4e1a\u52a1\u7ec6\u5206\u5bf9\u667a\u80fd\u5408\u7ea6\u8fdb\u884c\u62bd\u8c61\u548c\u5b9a\u4e49\uff0c\u5f62\u6210\u534f\u8bae\u5e76\u5229\u7528\u667a\u80fd\u5408\u7ea6\u8fdb\u884c\u534f\u8bae\u9a8c\u8bc1\u6027\u5de5\u4f5c\u548c\u6d4b\u8bd5\u3002
  6. \n
  7. \u5229\u7528\u667a\u80fd\u5408\u7ea6\u8fdb\u884c\u8de8\u94fe\u4ea4\u4e92\uff0c\u8de8\u94fe\u76f8\u5173\u529f\u80fd\u5728\u667a\u80fd\u5408\u7ea6\u4e2d\u7684\u7528\u6cd5\u5206\u6790\u548c\u7f16\u7801\u5b9e\u73b0\u3002
  8. \n
  9. \u5229\u7528 web3js/web3j \u3001golang \u7b49\u6846\u67b6\u6216\u8bed\u8a00\u5bf9\u667a\u80fd\u5408\u7ea6\u8fdb\u884c\u79c1\u94fe/\u6d4b\u8bd5\u94fe\u9a8c\u8bc1\u6027\u6d4b\u8bd5\uff0c\u4f7f\u7528 Truffle \u548c Openzeppelin \u5bf9\u73b0\u6709\u5408\u7ea6\u8fdb\u884c\u96c6\u6210\u5f00\u53d1\u548c\u4f18\u5316\u3002
  10. \n
\n

\u4efb\u804c\u8981\u6c42\uff1a

\n
    \n
  1. \u719f\u6089 Solidity \u7f16\u7a0b\uff0c\u80fd\u72ec\u7acb\u5b8c\u6210\u4e1a\u52a1\u903b\u8f91\u7684 solidity \u667a\u80fd\u5408\u7ea6\u7f16\u7a0b\u5b9e\u73b0\uff0c\u4e86\u89e3 EVM \u548c EOS \u865a\u62df\u673a\u57fa\u672c\u539f\u7406\u3002
  2. \n
  3. \u719f\u7ec3\u638c\u63e1\u533a\u5757\u94fe\u6280\u672f\uff0c\u719f\u6089\u667a\u80fd\u5408\u7ea6\u5f00\u53d1\u8bed\u8a00 Solidity \uff1b
  4. \n
  5. \u719f\u6089\u4f7f\u7528 Openzepplin \u8fdb\u884c\u667a\u80fd\u5408\u7ea6\u9879\u76ee\u8fed\u4ee3\u5f00\u53d1\u548c\u96c6\u6210\u3002
  6. \n
  7. \u719f\u6089\u5404\u79cd\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\uff0c\u5bf9\u5bc6\u7801\u5b66\u3001\u5b89\u5168\u534f\u8bae\u6709\u7814\u7a76\uff1b\u6df1\u5165\u4e86\u89e3\u4ee5\u592a\u574a\u7b49\u533a\u5757\u94fe\u7684\u539f\u7406\u3001\u673a\u5236\u548c\u76f8\u5173\u52a0\u5bc6\u7b97\u6cd5\uff1b
  8. \n
  9. \u719f\u6089 Truffle \u5f00\u53d1\u6846\u67b6\u3001\u80fd\u4f7f\u7528 Truffle \u6216 Hardhat \u8fdb\u884c\u667a\u80fd\u5408\u7ea6\u6d4b\u8bd5\u6848\u4f8b\u7684\u7f16\u5199\u548c\u9a8c\u8bc1\u3002
  10. \n
  11. \u5bf9\u4ee5\u592a\u574a\u5e95\u5c42\u534f\u8bae\uff0c\u8fd0\u884c\u673a\u5236\u548c\u5e95\u5c42\u5b9e\u73b0\u7b49\u6709\u4e00\u5b9a\u7684\u7814\u7a76\u5206\u6790\uff1b
  12. \n
  13. \u62e5\u6709\u4f18\u79c0\u7684\u53d1\u73b0\u548c\u89e3\u51b3\u95ee\u9898\u7684\u80fd\u529b\uff0c\u826f\u597d\u7684\u6c9f\u901a\u548c\u56e2\u961f\u534f\u4f5c\u80fd\u529b\uff0c\u80fd\u627f\u62c5\u4e00\u5b9a\u538b\u529b\uff1b
  14. \n
\n

\u52a0\u5206\u9879\uff1a

\n
    \n
  1. GitHub \u5f00\u6e90\u9879\u76ee\u4ee3\u7801\uff1b\u6709\u81ea\u5df1\u7684\u6280\u672f\u535a\u5ba2\u3002
  2. \n
  3. \u6709\u8fc7\u6210\u529f\u5177\u5907\u4e00\u5b9a\u7528\u6237\u91cf\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e ERC20/ERC721 Token \u5408\u7ea6\u3001DAPP \uff08\u591a\u91cd\u7b7e\u540d\u94b1\u5305\u3001\u6e38\u620f\u6216\u5176\u4ed6\uff09\u667a\u80fd\u5408\u7ea6\u3002\u5728 etherscan \u53ef\u6eaf\u6e90\u9879\u76ee\u6e90\u7801\u3002
  4. \n
  5. \u6df1\u523b\u7406\u89e3\u667a\u80fd\u5408\u7ea6\u5b89\u5168\u4f53\u7cfb\uff0c\u5e76\u80fd\u8be6\u7ec6\u9610\u8ff0\u5404\u79cd\u7c7b\u578b\u7684\u667a\u80fd\u5408\u7ea6\u6f0f\u6d1e\u7684\u653b\u9632\u63aa\u65bd
  6. \n
\n

\u8054\u7cfb\u65b9\u5f0f

\n

\u7535\u8bdd&\u5fae\u4fe1: 18320658783

\n" }, { "author": { "url": "member/freemoon", "name": "freemoon", "avatar": "https://cdn.v2ex.com/avatar/0a94/3887/328850_large.png?m=1773899137" }, "url": "t/901308", "date_modified": "2022-12-09T04:30:42+00:00", "content_html": "

\u6211\u6b63\u5728\u5b66\u4e60 solidity \uff0c\u53d1\u73b0\u56fd\u5185\u57fa\u672c\u6ca1\u6709\u5bf9\u5e94\u8bba\u575b\uff0c\u975e\u5e38\u963b\u788d\u56fd\u4eba\u5f00\u53d1\uff0c\u9042\u5efa\u7acb\u4e86\u4e00\u4e2a v \u7fa4\uff0c\u6709\u5174\u8da3\u7684\u6765\u52a0\uff0c\u5171\u5efa cn solidity \u5f00\u53d1\u793e\u533a\uff01\u521d\u671f\u5efa\u7acb\uff0c\u626b\u7801\u5373\u53ef\u52a0\u5165\uff01

\n

\"\u56fe\"

\n", "date_published": "2022-12-09T04:29:02+00:00", "title": "[Solidity \u7fa4] \u8bda\u9080\u5404\u4f4d\u5927\u4f6c\u52a0\u5165\uff01", "id": "t/901308" }, { "author": { "url": "member/0xVerin", "name": "0xVerin", "avatar": "https://cdn.v2ex.com/avatar/e30e/ff4c/583470_large.png?m=1653999391" }, "url": "t/856822", "title": "\u63a5 Dapp \u5f00\u53d1", "id": "t/856822", "date_published": "2022-06-01T14:47:51+00:00", "content_html": "

\u63a5 Dapp \u5f00\u53d1\uff0cDapp \u524d\u7aef\u5168\u4f1a\uff0c\u5408\u7ea6\u4f1a\u7684\u6709\uff1a\u8d28\u62bc\u6d41\u52a8\u6027\u6316\u77ff\uff0c\u82b1\u6837 ERC20 \uff0cNFT \u7b49\uff0c\u592a\u590d\u6742\u4e0d\u63a5\uff0c\u6ca1\u65f6\u95f4\u53bb\u505a\u3002

\n" }, { "author": { "url": "member/notot", "name": "notot", "avatar": "https://cdn.v2ex.com/avatar/2684/9aab/550273_large.png?m=1775521868" }, "url": "t/856187", "date_modified": "2022-05-30T04:22:55+00:00", "content_html": "

\u5bfc\u8bfb

\n

\u6b64\u6559\u7a0b\u9002\u5408\u81f3\u5c11\u4e86\u89e3\u8fc7\u4e00\u70b9\u5408\u7ea6\u76f8\u5173\u77e5\u8bc6\uff0c\u5bf9\u533a\u5757\u94fe\u6709\u57fa\u672c\u5171\u8bc6\u540c\u5b66\u8fdb\u884c\u89c2\u770b\u3002

\n

\u4e0d\u7ba1\u4f60\u662f\u9700\u8981\u9605\u8bfb\u5408\u7ea6\u6e90\u7801\uff0c\u4ea6\u6216\u662f\u9700\u8981\u7f16\u5199\u5408\u7ea6\u3002\u8fd9\u4efd\u6307\u5357\u90fd\u4f1a\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u8fd9\u4efd\u4e3a\u4e2a\u4eba\u6574\u7406\u6bd4\u4e0d\u4e0a\u5b98\u65b9\u6587\u6863\uff0c\u4f46\u662f\u5bf9\u7279\u522b\u9700\u8981\u6ce8\u610f\u7684\u77e5\u8bc6\u70b9\u505a\u4e86\u8865\u5145\u8bf4\u660e\uff0c\u53ef\u7528\u6b64\u6587\u6863\u8fdb\u884c\u8fc7\u5ea6\u3002\u5728\u540e\u7eed\u6709\u66f4\u52a0\u7ec6\u8282\u7684\u77e5\u8bc6\u70b9\u9700\u8981\u67e5\u8be2\u65f6\uff0c\u53ef\u5230\u5b98\u65b9\u6587\u6863\u8fdb\u884c\u67e5\u9605\u3002

\n

Official Solidity Docs - EN

\n

Community Solidity Docs - ZH

\n

01. Tutorial

\n

1.1 \u57fa\u7840\u8bed\u6cd5

\n
pragma solidity >=0.4.0 <0.6.0;\ncontract SimpleStorage {\n uint storedData;\n function set(uint x) public {\n storedData = x;\n }\n function get() public view returns (uint) {\n return storedData;\n }\n}\n
\n

\u4e0a\u9762\u662f\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u5408\u7ea6

\n

Pragma

\n

\u7b2c\u4e00\u884c\u8868\u793a\u5408\u7ea6\u5bf9\u5e94\u7684 solidity \u7248\u672c\uff0c\u5927\u4e8e\u7b49\u4e8e 0.4.0 \u4f46\u662f\u5c0f\u4e8e 0.6.0

\n

\u4e5f\u53ef\u4ee5\u50cf\u4e0b\u9762\u8fd9\u79cd\u5199\u6cd5

\n
pragma solidity ^0.4.0;\n
\n

Contract

\n

\u5408\u7ea6\u672c\u8d28\u4e0a\u5c31\u662f\u8fd0\u884c\u5728\u533a\u5757\u94fe\u4e0a\u7684\u4e00\u6bb5\u4ee3\u7801\uff0c\u5982\u4e0a\u65b9\u6240\u793a unit storedData \u4ee3\u8868\u4e86\u5b83\u662f\u8fd0\u884c\u4e0a\u533a\u5757\u94fe\u4e0a\u7684\u4e00\u4e2a\u53d8\u91cf\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0b\u65b9\u7684 get set \u6765\u5bf9\u4ed6\u8fdb\u884c\u4fee\u6539\u3002

\n

Import

\n

\u5728 solidity \u8bed\u8a00\u4e2d\uff0c\u60f3\u8981\u4f7f\u7528\u5176\u4ed6\u6a21\u5757\u7684\u65b9\u6cd5\u6216\u5c5e\u6027\uff0c\u5219\u9700\u8981\u8fdb\u884c\u5012\u5165\uff0c\u603b\u5171\u7531\u4e24\u79cd\u65b9\u6cd5

\n
import \"filename\"\n
\n

\u4e5f\u53ef\u4ee5\u4f7f\u7528

\n
import * as symbolName from \"filename\";\n
\n

1.2 \u7b2c\u4e00\u4e2a\u7a0b\u5e8f

\n
\n

\u6ce8\u610f\uff1asolidity \u4e0d\u50cf JS JAVA \u7b49\u8bed\u8a00\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u672c\u5730\u8fd0\u884c\uff0c\u5b83\u66f4\u591a\u7684\u662f\u9700\u8981\u50cf EVM \u8fd9\u6837\u7684\u73af\u5883\u624d\u80fd\u8fd0\u884c\uff0c\u6240\u4ee5\u5728\u521a\u5f00\u59cb\u7ec3\u4e60\u7684\u65f6\u5019\uff0c\u6700\u597d\u662f\u7528\u6bd4\u8f83\u7b80\u5355\uff0c\u80fd\u76f4\u89c2\u770b\u5230\u7ed3\u679c\u7684\u7f16\u8f91\u5668\u3002

\n
\n

\u6253\u5f00\u9875\u9762 Remix IDE\uff0c\u8fd0\u884c\u6211\u4eec\u7684\u4ee3\u7801\u3002

\n

Step 1

\n

\u5c06\u4e0b\u65b9 Example \u4e2d\u7684\u4ee3\u7801\u62f7\u8d1d\u5230 Remix \u4e2d

\n

Example

\n
pragma solidity ^0.5.0;\ncontract SolidityTest {\n constructor() public{\n }\n function getResult() public view returns(uint){\n uint a = 1;\n uint b = 2;\n uint result = a + b;\n return result;\n }\n}\n
\n

Step 2

\n

\u5207\u6362\u5230 \u7f16\u8bd1 Tab \uff0c\u70b9\u51fb\u7f16\u8bd1

\n

\"image-20220524153016705\"

\n

Step 3

\n

\u70b9\u51fb\u90e8\u7f72

\n

\"image-20220524153348647\"

\n

Step 4

\n

\u90e8\u7f72\u5b8c\u6210\u4e4b\u540e\uff0c\u4e0b\u65b9\u5c31\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u90e8\u7f72\u540e\u7684\u5408\u7ea6

\n

\"image-20220524153639653\"

\n

\u7136\u540e\u5c06\u5408\u7ea6\u5c55\u5f00,\u5c55\u5f00\u4e4b\u540e\u6211\u4eec\u5c31\u53ef\u4ee5\u5728\u8fd9\u91cc\u9762\u8c03\u7528\u5408\u7ea6\u4e2d\u4ee3\u7801\u3002

\n

\"image-20220524153706691\"

\n

\u70b9\u51fb getResult

\n

\"image-20220524153724296\"

\n

\u5c31\u80fd\u5f97\u5230\u7ed3\u679c\u3002\u8fd9\u6837\u6211\u4eec\u5c31\u5b8c\u6210\u4e86\u7b2c\u4e00\u4e2a solidity \u7a0b\u5e8f\u7684\u7f16\u5199\u548c\u90e8\u7f72\u6d4b\u8bd5\u3002

\n

1.3 \u6ce8\u91ca

\n

\u652f\u6301\u4e24\u79cd\u5f62\u5f0f

\n
function getResult() public view returns(uint){\n // This is a comment. It is similar to comments in C++\n\n /*\n * This is a multi-line comment in solidity\n * It is very similar to comments in C Programming\n */\n uint a = 1;\n uint b = 2;\n uint result = a + b;\n return result;\n}\n
\n

1.4 \u7c7b\u578b

\n

types

\n

\u5730\u5740 Address

\n

address \u4fdd\u5b58\u4ee3\u8868\u4ee5\u592a\u574a\u5730\u5740\u5927\u5c0f\u7684 20 \u5b57\u8282\u503c\u3002 \u4e00\u4e2a\u5730\u5740\u53ef\u4ee5\u4f7f\u7528 .balance \u65b9\u6cd5\u83b7\u53d6\u4f59\u989d\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 .transfer \u65b9\u6cd5\u5c06\u4f59\u989d\u8f6c\u79fb\u5230\u53e6\u4e00\u4e2a\u5730\u5740\u3002

\n
address x = 0x212;\naddress myAddress = this;\nif (x.balance < 10 && myAddress.balance >= 10) x.transfer(10);\n
\n

\"image-20220527113057200\"

\n

address \u8fd9\u91cc\u5bb9\u6613\u8ba9\u4eba\u6709\u70b9\u8bef\u89e3\uff0c\u660e\u660e\u5b58\u5165\u7684\u662f 0x1341243243... \u8fd9\u6837\u7684\u4e00\u4e2a\u4e1c\u897f\uff0c\u4f46\u662f\u5374\u53ef\u4ee5\u76f4\u63a5\u70b9\u51fa\u65b9\u6cd5 balance \u548c transfer\u3002\u8fd9\u91cc\u9700\u8981\u6d88\u5316\u4e00\u4e0b\uff0c\u4e0d\u7136\u540e\u9762\u5bb9\u6613\u61f5\u3002

\n

\u8fd9\u91cc\u7684 address \u5bf9\u8c61\u6211\u4eec\u53ef\u4ee5\u7406\u89e3\u4e3a\u662f\u4e00\u4e2a\u5305\u88c5\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u76f4\u63a5\u7406\u89e3 address \u4e3a\u4e00\u4e2a\u7c7b\uff0c\u4ed6\u672c\u8eab\u5c31\u5177\u5907\u5f88\u591a\u65b9\u6cd5\u3002\u53ea\u4e0d\u8fc7\u5728\u521d\u59cb\u5316\u7684\u65f6\u5019\u8ddf\u4f20\u7edf\u7684 Struct \u7ed3\u6784\u7684\u6570\u636e\u4e0d\u4e00\u6837\u3002\u53ea\u9700\u8981\u8bbe\u7f6e\u5730\u5740\u5c31\u53ef\u4ee5\u4e86\uff0c\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u5e2e\u6211\u4eec\u5904\u7406\u3002

\n

address \u4e2d\u6240\u6709\u7684\u53ef\u7528\u65b9\u6cd5

\n

<address>.balance (uint256):

\n

\u4ee5 Wei \u4e3a\u5355\u4f4d\u7684 \u5730\u5740\u7c7b\u578b \u7684\u4f59\u989d\u3002

\n

<address>.transfer(uint256 amount):

\n

\u5411 \u5730\u5740\u7c7b\u578b \u53d1\u9001\u6570\u91cf\u4e3a amount \u7684 Wei \uff0c\u5931\u8d25\u65f6\u629b\u51fa\u5f02\u5e38\uff0c\u53d1\u9001 2300 gas \u7684\u77ff\u5de5\u8d39\uff0c\u4e0d\u53ef\u8c03\u8282\u3002

\n

<address>.send(uint256 amount) returns (bool):

\n

\u5411 \u5730\u5740\u7c7b\u578b \u53d1\u9001\u6570\u91cf\u4e3a amount \u7684 Wei \uff0c\u5931\u8d25\u65f6\u8fd4\u56de false\uff0c\u53d1\u9001 2300 gas \u7684\u77ff\u5de5\u8d39\u7528\uff0c\u4e0d\u53ef\u8c03\u8282\u3002

\n

<address>.call(...) returns (bool):

\n

\u53d1\u51fa\u4f4e\u7ea7\u51fd\u6570 CALL\uff0c\u5931\u8d25\u65f6\u8fd4\u56de false\uff0c\u53d1\u9001\u6240\u6709\u53ef\u7528 gas \uff0c\u53ef\u8c03\u8282\u3002

\n

<address>.callcode(...) returns (bool)\uff1a

\n

\u53d1\u51fa\u4f4e\u7ea7\u51fd\u6570 CALLCODE\uff0c\u5931\u8d25\u65f6\u8fd4\u56de false\uff0c\u53d1\u9001\u6240\u6709\u53ef\u7528 gas \uff0c\u53ef\u8c03\u8282\u3002

\n

<address>.delegatecall(...) returns (bool):

\n

\u53d1\u51fa\u4f4e\u7ea7\u51fd\u6570 DELEGATECALL\uff0c\u5931\u8d25\u65f6\u8fd4\u56de false\uff0c\u53d1\u9001\u6240\u6709\u53ef\u7528 gas \uff0c\u53ef\u8c03\u8282\u3002

\n

1.5 \u53d8\u91cf

\n\"image-20220524155201718\"\n
\n

\u6b64\u5c0f\u8282\u975e\u5e38\u91cd\u8981\u3002

\n
\n

\u5728 Solidity \u4e2d\u603b\u5171\u6709 3 \u79cd\u53d8\u91cf

\n\n

\u72b6\u6001\u53d8\u91cf

\n

\u8868\u660e\u5b58\u50a8\u5728\u5408\u7ea6\u4e2d\u7684\u53d8\u91cf\uff0c\u4ec0\u4e48\u53eb\u5b58\u50a8\u5728\u5408\u7ea6\u4e2d\u5462\uff0c\u5176\u5b9e\u5c31\u76f8\u5f53\u4e8e Java \u91cc\u9762\u7684\u6210\u5458\u53d8\u91cf\uff0c\u5728 solidity \u4e2d\u7684\u5199\u6cd5\u5982\u4e0b

\n
pragma solidity ^0.5.0;\ncontract SolidityTest {\n uint storedData; // State variable\n constructor() public {\n storedData = 10; // Using State variable\n }\n}\n
\n

\u672c\u5730\u53d8\u91cf

\n

\u5176\u503c\u4ec5\u5728\u5b9a\u4e49\u5b83\u7684\u51fd\u6570\u5185\u53ef\u7528\u7684\u53d8\u91cf\u3002 \u51fd\u6570\u53c2\u6570\u59cb\u7ec8\u662f\u8be5\u51fd\u6570\u7684\u672c\u5730\u53c2\u6570\u3002\u5176\u5b9e\u8bf4\u767d\u4e86\u5c31\u662f\u5c40\u90e8\u53d8\u91cf\uff0c\u5c31\u662f\u5199\u5728\u65b9\u6cd5\u91cc\u9762\u7684\u3002

\n
pragma solidity ^0.5.0;\ncontract SolidityTest {\n uint storedData; // State variable\n constructor() public {\n storedData = 10; \n }\n function getResult() public view returns(uint){\n uint a = 1; // local variable\n uint b = 2;\n uint result = a + b;\n return result; //access the local variable\n }\n}\n
\n

\u5168\u5c40\u53d8\u91cf [\u91cd\u8981\u203c\ufe0f]

\n

\"image-20220527113057200\"

\n

\u5168\u5c40\u53d8\u91cf\u662f\u5b58\u5728\u4e8e\u5168\u5c40\u5de5\u4f5c\u7a7a\u95f4\u4e2d\u7684\u7279\u6b8a\u53d8\u91cf\uff0c\u5b83\u4eec\u63d0\u4f9b\u5173\u4e8e\u533a\u5757\u94fe\u548c\u4ea4\u6613\u5c5e\u6027\u7684\u4fe1\u606f\u3002\u8bf4\u767d\u4e86\u5c31\u662f\u4e0d\u9700\u8981\u58f0\u660e\uff0c\u6709\u70b9\u7c7b\u4f3c\u4e8e Node \u91cc\u9762\u7684 Process \uff0c\u6d4f\u89c8\u5668\u91cc\u9762\u7684 Windows \uff0c\u53ef\u4ee5\u76f4\u63a5\u62ff\u6765\u4f7f\u7528\u3002

\n

Solidity \u4e2d\u7684\u5168\u5c40\u53d8\u91cf\u6709\u4e0b\u9762\u51e0\u79cd\u3002

\n\n

\u770b\u4e00\u4e0b\u5728\u5408\u7ea6\u4e2d\u5982\u4f55\u4f7f\u7528 \u5168\u5c40\u53d8\u91cf

\n
pragma solidity ^0.5.0;\ncontract SolidityTest {\n\n function getNowTime() public view returns(uint) {\n return now;\n }\n\n function getSender() public view returns (address payable) {\n return msg.sender;\n }\n\n function getGaslimit() public view returns (uint) {\n return block.gaslimit;\n }\n}\n
\n

\u7136\u540e\u5728\u4ece\u65b0\u70b9\u51fb \u90e8\u7f72\uff0c\u6309\u7167\u4e0a\u9762\u8bb2\u8fc7\u7684\u6b65\u9aa4

\n

\"image-20220524161629834\"

\n

\u7136\u540e\u8fd0\u884c\u90e8\u7f72\u540e\u7684\u5408\u7ea6\u3002

\n

\u53d8\u91cf\u547d\u540d\u89c4\u8303

\n\n

1.6 \u53d8\u91cf\u4f5c\u7528\u57df

\n

\u5728 1.5 \u5c0f\u8282\u4e2d\u8bb2\u5230 Solidity \u4e2d\u6709\u4e09\u79cd\u7c7b\u578b\u7684\u53d8\u91cf

\n\n

\u672c\u5730\u53d8\u91cf\u7684\u4f5c\u7528\u4e8e\u53ea\u5b58\u5728\u4e8e\u65b9\u6cd5\u4e2d\uff0c\u4f46\u662f\u72b6\u6001\u53d8\u91cf\u6709\u4e09\u79cd\u4f5c\u7528\u57df\u3002

\n\n
pragma solidity ^0.5.0;\ncontract C {\n uint public data = 30;\n uint internal iData= 10;\n \n function x() public returns (uint) {\n data = 3; // internal access\n return data;\n }\n}\ncontract Caller {\n C c = new C();\n function f() public view returns (uint) {\n return c.data(); //external access\n }\n}\ncontract D is C {\n function y() public returns (uint) {\n iData = 3; // internal access\n return iData;\n }\n function getResult() public view returns(uint){\n uint a = 1; // local variable\n uint b = 2;\n uint result = a + b;\n return storedData; //access the state variable\n }\n}\n
\n

\u4e0a\u65b9 Example \u7684\u5408\u7ea6\u5173\u7cfb\u4e3a

\n\n

1.7 \u7701\u7565\u7ae0\u8282

\n\n

\u4ee5\u4e0a\u5185\u5bb9\u90fd\u6bd4\u8f83\u5e38\u89c4\uff0c\u548c\u5e73\u5e38\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u8bed\u6cd5\u5dee\u5f02\u4e0d\u5927\u3002\u5927\u5bb6\u6709\u5174\u8da3\u53ef\u4ee5\u67e5\u67e5\u5b98\u65b9\u6587\u6863\uff0c\u8fd9\u91cc\u5c31\u4e0d\u5728\u8d58\u8ff0\u3002

\n

1.8 struct

\n
struct struct_name { \n type1 type_name_1;\n type2 type_name_2;\n type3 type_name_3;\n}\n
\n

struct \u53ef\u4ee5\u7406\u89e3\u4e3a\u591a\u79cd\u7c7b\u578b\u7684\u4e00\u4e2a\u5305\u88c5\uff0c\u5c31\u548c\u5305\u88c5\u6570\u636e\u7c7b\u578b\u662f\u4e00\u6837\u7684\u3002

\n

Eample

\n
pragma solidity ^0.5.0;\n\ncontract test {\n struct Book { \n string title;\n string author;\n uint book_id;\n }\n Book book;\n\n function setBook() public {\n book = Book('Learn Java', 'TP', 1);\n }\n function getBookId() public view returns (uint) {\n return book.book_id;\n }\n}\n
\n

1.9 Mapping

\n

mapping(_KeyType => _ValueType)

\n\n

\u53ef\u4ee5\u7406\u89e3\u4e3a Hash \u7c7b\u578b

\n
pragma solidity ^0.5.0;\n\ncontract LedgerBalance {\n mapping(address => uint) public balances;\n\n function updateBalance(uint newBalance) public {\n balances[msg.sender] = newBalance;\n }\n}\ncontract Updater {\n function updateBalance() public returns (uint) {\n LedgerBalance ledgerBalance = new LedgerBalance();\n ledgerBalance.updateBalance(10);\n return ledgerBalance.balances(address(this));\n }\n}\n
\n", "date_published": "2022-05-30T04:21:56+00:00", "title": "Solidity \u5165\u95e8\u6559\u7a0b \u7b2c\u4e00\u5c0f\u8282\uff08\u4e3b\u9898\u6709\u5b57\u6570\u9650\u5236\uff09", "id": "t/856187" }, { "author": { "url": "member/Livid", "name": "Livid", "avatar": "https://cdn.v2ex.com/avatar/c4ca/4238/1_large.png?m=1776858751" }, "url": "t/830084", "title": "\u6700\u8fd1\u4e0a\u7ebf\u7684 Azuki \u9879\u76ee\u4e0d\u4ec5\u7f8e\u672f\u5f88\u5f3a\uff0c Solidity \u7a0b\u5e8f\u4e5f\u5f88\u5f3a", "id": "t/830084", "date_published": "2022-01-23T07:53:15+00:00", "content_html": "

https://twitter.com/AzukiZen/status/1485026548289732608

\n

https://github.com/chiru-labs/ERC721A

\n" }, { "author": { "url": "member/xilibi2003", "name": "xilibi2003", "avatar": "https://cdn.v2ex.com/avatar/0bfd/d6d1/221629_large.png?m=1676021830" }, "url": "t/562435", "date_modified": "2022-01-23T08:24:06+00:00", "content_html": "

Solidity \u6700\u65b0 0.5.8 \u4e2d\u6587\u6587\u6863\u53d1\u5e03\u5566~~~ \uff0c \u8fd9\u4e0d\u5355\u662f\u4e00\u4efd Solidity \u901f\u67e5\u624b\u518c\uff0c\u66f4\u662f\u4e00\u4efd\u6df1\u5165\u4ee5\u592a\u574a\u667a\u80fd\u5408\u7ea6\u5f00\u53d1\u5b9d\u5178\u3002

\n

\u7ffb\u8bd1\u8bf4\u660e

\n

Solidity \u6700\u65b0 0.5.8 \u4e2d\u6587\u6587\u6863 \u6839\u636e\u5f53\u524d\u00a0\u6700\u65b0\u5b98\u65b9\u7248\u672c v0.5.8\u00a0\u8fdb\u884c\u7ffb\u8bd1\uff0c\u672c\u7ffb\u8bd1\u6700\u521d\u00a0HiBlock\u00a0\u793e\u533a\u53d1\u8d77\uff0c\u540e\u7ecf\u8fc7\u00a0\u6df1\u5165\u6d45\u51fa\u533a\u5757\u94fe\u793e\u533a\u00a0\u793e\u533a\u6210\u5458\u6839\u636e\u6700\u65b0\u7248\u672c\u8865\u5145\u7ffb\u8bd1\u3002

\n

\u5927\u90e8\u5206\u7684\u8bd1\u8005\uff0c\u90fd\u662f\u56fd\u5185\u9876\u5c16\u7684\u4ee5\u592a\u574a\u5f00\u53d1\u548c\u7814\u7a76\u4eba\u5458\uff0c\u90e8\u5206\u8bd1\u8005\u5982\u4e0b\uff1a

\n\n

\u611f\u8c22\u6240\u6709\u7684\u8bd1\u8005\u8d21\u732e\uff0c\u732e\u82b1~ \u732e\u82b1~

\n

\u8fd9\u4efd\u6587\u6863\u65e0\u7591\u662f\u6700\u65b0\u8d28\u91cf\u6700\u597d\u7684\u4e2d\u6587\u6587\u6863\uff0c\u672c\u6587\u4ec5\u4ec5\u662f\u90e8\u5206\u6458\u8981\u548c\u76ee\u5f55\uff0c \u5b8c\u6574\u6587\u6863\u8bf7\u524d\u5f80 https://learnblockchain.cn/docs/solidity/ \u3002

\n

\u7ffb\u8bd1\u5de5\u4f5c\u662f\u4e00\u4e2a\u6301\u7eed\u7684\u8fc7\u7a0b\uff08\u8fd9\u4efd\u6587\u6863\u76ee\u524d\u4e5f\u8fd8\u6709\u90e8\u5206\u672a\u5b8c\u6210\uff09\uff0c\u6211\u4eec\u70ed\u60c5\u9080\u8bf7\u70ed\u7231\u533a\u5757\u94fe\u6280\u672f\u7684\u5c0f\u4f19\u4f34\u4e00\u8d77\u53c2\u4e0e\uff0c\u6b22\u8fce\u52a0\u5165\u6211\u4eec Group\uff1a https://github.com/lbc-team\u3002

\n

\u672c\u4e2d\u6587\u6587\u6863\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\uff0c\u82f1\u4e2d\u76f4\u8bd1\uff0c\u4f46\u6709\u65f6\u4e3a\u4e86\u66f4\u597d\u7684\u7406\u89e3\u4e5f\u4f1a\u4f7f\u7528\u610f\u8bd1\uff0c\u5982\u9700\u8f6c\u8f7d\u8bf7\u8054\u7cfb Tiny \u718a\uff08\u5fae\u4fe1\uff1axlbxiong \uff09.

\n

Solidity \u8bed\u8a00\u7b80\u4ecb \u53ca \u6587\u6863\u76ee\u5f55

\n

Solidity \u662f\u4e00\u95e8\u9762\u5411\u5408\u7ea6\u7684\u3001\u4e3a\u5b9e\u73b0\u667a\u80fd\u5408\u7ea6\u800c\u521b\u5efa\u7684\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\u3002\u8fd9\u95e8\u8bed\u8a00\u53d7\u5230\u4e86 C++\uff0cPython \u548c Javascript \u8bed\u8a00\u7684\u5f71\u54cd\uff0c\u8bbe\u8ba1\u7684\u76ee\u7684\u662f\u80fd\u5728\u4ee5\u592a\u574a\u865a\u62df\u673a\uff08 EVM \uff09]\u4e0a\u8fd0\u884c\u3002

\n

\u8981\u7406\u89e3\u667a\u80fd\u5408\u7ea6\u53ca\u865a\u62df\u673a\u662f\u600e\u4e48\u8fd0\u884c\uff0c\u63a8\u8350\u8fd9\u4e24\u7bc7\u975e\u5e38\u597d\u7684\u6587\u7ae0\u00a0\u5b8c\u5168\u7406\u89e3\u4ee5\u592a\u574a\u667a\u80fd\u5408\u7ea6\u00a0\u53ca\u00a0\u6df1\u5165\u6d45\u51fa\u4ee5\u592a\u574a\u865a\u62df\u673a

\n

Solidity \u662f\u9759\u6001\u7c7b\u578b\u8bed\u8a00\uff0c\u652f\u6301\u7ee7\u627f\u3001\u5e93\u548c\u590d\u6742\u7684\u7528\u6237\u5b9a\u4e49\u7c7b\u578b\u7b49\u7279\u6027\uff0c \u4ee5\u4e0b\u662f\u90e8\u5206\u76ee\u5f55\u3002

\n

\u6587\u6863\u76ee\u5f55

\n\n

\u6df1\u5165\u6d45\u51fa\u533a\u5757\u94fe - \u7cfb\u7edf\u5b66\u4e60\u533a\u5757\u94fe\uff0c\u5b66\u533a\u5757\u94fe\u90fd\u5728\u8fd9\u91cc\uff0c\u6253\u9020\u6700\u597d\u7684\u533a\u5757\u94fe\u6280\u672f\u535a\u5ba2\u3002

\n", "date_published": "2019-05-09T02:55:28+00:00", "title": "\u793e\u533a\u5c0f\u4f19\u4f34\u901a\u529b\u5408\u4f5c\u7684\u7ed3\u6676\uff1a\u667a\u80fd\u5408\u7ea6\u7f16\u7a0b\u8bed\u8a00 Solidity \u6700\u65b0 0.5.8 \u4e2d\u6587\u6587\u6863 \u53d1\u5e03", "id": "t/562435" }, { "author": { "url": "member/whoami9894", "name": "whoami9894", "avatar": "https://cdn.v2ex.com/avatar/98db/b7ad/282705_large.png?m=1583073579" }, "url": "t/517929", "date_modified": "2022-01-23T08:22:06+00:00", "content_html": "
pragma solidity ^0.4.23;\n\ncontract Preservation {\n\n // public library contracts \n address public timeZone1Library;\n address public timeZone2Library;\n address public owner; \n uint storedTime;\n // Sets the function signature for delegatecall\n bytes4 constant setTimeSignature = bytes4(keccak256(\"setTime(uint256)\"));\n\n event FLAG(string b64email, string slogan);\n\n constructor(address _timeZone1LibraryAddress, address _timeZone2LibraryAddress) public {\n timeZone1Library = _timeZone1LibraryAddress; \n timeZone2Library = _timeZone2LibraryAddress; \n owner = msg.sender;\n }\n\n // set the time for timezone 1\n function setFirstTime(uint _timeStamp) public {\n timeZone1Library.delegatecall(setTimeSignature, _timeStamp);\n }\n\n // set the time for timezone 2\n function setSecondTime(uint _timeStamp) public {\n timeZone2Library.delegatecall(setTimeSignature, _timeStamp);\n }\n\n function CaptureTheFlag(string b64email) public{\n require (owner == msg.sender);\n emit FLAG(b64email, \"Congratulations to capture the flag!\");\n }\n}\n\n// Simple library contract to set the time\ncontract LibraryContract {\n\n // stores a timestamp \n uint storedTime; \n\n function setTime(uint _time) public {\n storedTime = _time;\n }\n}\n
\n

\u5bf9\u4ee5\u592a\u574a\u76f8\u5173\u4e00\u7a8d\u4e0d\u901a\uff0c\u770b\u4e86\u4e0d\u5c11\u6587\u7ae0\u8fd8\u662f\u6709\u70b9\u6478\u4e0d\u7740\u5934\u8111....

\n

\u8fd9\u662f\u533a\u5757\u94fe\u5b89\u5168\u60f3\u5173\u7684\uff0c\u60f3\u8bf7\u6559\u4e00\u4e0b\u8fd9\u6bb5\u5408\u7ea6\u4ee3\u7801\u653e\u5728 Remix \u4e0a\u7f16\u8bd1\u8fd0\u884c\u540e\u8c03\u7528CaptureTheFlag\u51fd\u6570\u524d\u6709\u4ec0\u4e48\u7ea6\u675f\u5417\uff08\u8fd9\u91cc\u7684\u76ee\u7684\u662f\u8c03\u7528\u8be5\u51fd\u6570\uff09\uff0c\u6211\u7684\u731c\u60f3\u8fd9\u91cc\u65f6\u95f4\u6233\u53ef\u80fd\u4e0euint256\u6ea2\u51fa\u6709\u5173

\n", "date_published": "2018-12-15T15:37:19+00:00", "title": "\u60f3\u8bf7\u6559\u4e00\u4e2a solidity \u4ee5\u592a\u574a\u5408\u7ea6\u7684\u4ee3\u7801\u95ee\u9898", "id": "t/517929" }, { "author": { "url": "member/konakona", "name": "konakona", "avatar": "https://cdn.v2ex.com/avatar/15c0/8959/38523_large.png?m=1773655506" }, "url": "t/510462", "date_modified": "2022-01-23T08:24:00+00:00", "content_html": "\u6709\u4e9b\u5f00\u53d1\u95ee\u9898\u60f3\u54a8\u8be2\u3002\u592a\u591a\u5751\u4e86\u3002", "date_published": "2018-11-22T08:44:34+00:00", "title": "\u8bf7\u95ee\u6709\u6ca1\u6709 ETH solidity \u7684\u7fa4\u6216\u8005\u6d3b\u8dc3\u793e\u533a\u5462\uff1f", "id": "t/510462" }, { "author": { "url": "member/xcstream", "name": "xcstream", "avatar": "https://cdn.v2ex.com/avatar/9d55/5d90/116896_large.png?m=1465363453" }, "url": "t/476633", "date_modified": "2022-01-23T08:22:02+00:00", "content_html": "

\u636e\u8bf4 now difficulty \u90fd\u4e0d\u592a\u5b89\u5168

\n", "date_published": "2018-08-03T08:02:07+00:00", "title": "solidity \u5982\u4f55\u6b63\u786e\u7684\u4ea7\u751f\u968f\u673a\u6570", "id": "t/476633" } ] } ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86