{"id":244729,"date":"2023-03-29T12:35:23","date_gmt":"2023-03-29T04:35:23","guid":{"rendered":"https:\/\/www.idc.net\/help\/244729\/"},"modified":"2023-03-29T12:35:23","modified_gmt":"2023-03-29T04:35:23","slug":"%e4%bb%8e%e9%9b%b6%e5%88%b0%e8%8b%b1%e9%9b%84%ef%bc%9a%e4%bd%bf%e7%94%a8infura%e5%92%8cpython%e5%ad%a6%e4%b9%a0%e5%bc%80%e5%8f%91web3","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/244729\/","title":{"rendered":"\u4ece\u96f6\u5230\u82f1\u96c4\uff1a\u4f7f\u7528Infura\u548cPython\u5b66\u4e60\u5f00\u53d1Web3"},"content":{"rendered":"<p>\u8bd1\u8005 | \u674e\u777f<\/p>\n<p>\u5ba1\u6821 | \u91cd\u697c<\/p>\n<p><span style=\"font-size: 13px\">Web3\u3001\u533a\u5757\u94fe\u6280\u672f\u548c\u52a0\u5bc6\u8d27\u5e01\u5982\u4eca\u90fd\u662f\u4ee4\u4eba\u5173\u6ce8\u7684\u70ed\u95e8\u8bdd\u9898\u3002\u6280\u672f\u3001\u5e94\u7528\u3001\u751f\u6001\u7cfb\u7edf\u4ee5\u53ca\u5bf9\u793e\u4f1a\u7684\u5f71\u54cd\u90fd\u5728\u4ee5\u60ca\u4eba\u7684\u901f\u5ea6\u53d1\u5c55\u3002\u672c\u6587\u5c06\u4ece\u5f00\u53d1\u4eba\u5458<\/span><span style=\"font-size: 13px\">Alvin Lee<\/span><span style=\"font-size: 13px\">\u7684\u89d2\u5ea6\u6765\u8ba8\u8bba\u5982\u4f55\u5b66\u4e60\u5f00\u53d1<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\uff0c\u867d\u7136\u4ed6\u5f00\u53d1\u7ecf\u9a8c\u4e30\u5bcc\uff0c\u4f46\u662f\u5728\u5f00\u53d1<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u65b9\u9762\u5219\u662f\u4e00\u540d\u65b0\u624b\u3002\u672c\u6587\u5c06\u4e86\u89e3<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u5f00\u53d1\u7684\u5148\u51b3\u6761\u4ef6\uff0c\u5982\u4f55\u4f7f\u7528Python\u901a\u8fc7<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u7684\u9876\u7ea7API\u670d\u52a1Infura\u8bbf\u95ee\u533a\u5757\u94fe\uff0c\u6700\u540e\u4ecb\u7ecd\u7528\u4e8e\u7ba1\u7406\u94b1\u5305\u7684\u4e00\u4e2a\u7b80\u5355\u9879\u76ee\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p style=\"text-align:center\">\n<h4>\u5982\u4f55\u5f00\u59cb<\/h4>\n<p><span style=\"font-size: 13px\">\u5c3d\u7ba1<\/span><span style=\"font-size: 13px\">Alvin<\/span><span style=\"font-size: 13px\"> <\/span><span style=\"font-size: 13px\">Lee<\/span><span style=\"font-size: 13px\">\u4ece20\u4e16\u7eaa90\u5e74\u4ee3\u672b\u5c31\u5f00\u59cb\u8fdb\u884c\u7f16\u7a0b\uff0c\u4f46\u5728<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u4e16\u754c\u91cc\uff0c\u4ed6\u5374\u662f\u4e00\u540d\u521d\u5b66\u8005\u3002\u4ed6\u5e76\u4e0d\u662f\u4e13\u5bb6\uff0c\u6240\u4ee5\u4e0d\u4f1a\u8bd5\u56fe\u89e3\u91ca<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u57fa\u672c\u539f\u7406\u3002\u4f46\u5e02\u9762\u4e0a\u6709\u5f88\u591a\u5f88\u597d\u7684\u6307\u5357\u548c\u6559\u7a0b\uff0c\u56e0\u6b64\u4ed6\u5efa\u8bae\u4eceInfura\u6587\u6863\u5f00\u59cb\uff0c\u5b83\u975e\u5e38\u5168\u9762\u4e14\u6613\u4e8e\u7406\u89e3\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u5982\u679c\u7528\u6237\u559c\u6b22\u66f4\u4e92\u52a8\u7684\u5b66\u4e60\u65b9\u5f0f\uff0c\u4e5f\u53ef\u4ee5\u4ece\u6280\u672f\u793e\u533a\u83b7\u5f97\u652f\u6301\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u73b0\u5728<\/span><span style=\"font-size: 13px\">\uff0c\u5b66\u4e60<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u5148\u4ece\u4e00\u4e9b\u57fa\u7840\u77e5\u8bc6\u5f00\u59cb\u3002\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2aInfura\u8d26\u6237\uff0c\u4e00\u4e2a\u5b58\u50a8\u52a0\u5bc6\u8d27\u5e01\u7684\u94b1\u5305\uff0c\u5f53\u7136\u8fd8\u9700\u8981\u4e00\u4e9b\u94b1\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<h4>\u521b\u5efaInfura\u8d26\u6237<\/h4>\n<p><span style=\"font-size: 13px\">Infura\u516c\u53f8\u662f\u533a\u5757\u94feAPI\u548c\u5f00\u53d1\u4eba\u5458<\/span><span style=\"font-size: 13px\">\u4f7f\u7528<\/span><span style=\"font-size: 13px\">\u5de5\u5177\u7684\u63d0\u4f9b\u5546\u3002\u8fd9\u610f\u5473\u7740\u5982\u679c\u670d\u52a1\u5546\u60f3\u8bbf\u95ee\u533a\u5757\u94fe\uff0c\u4e0d\u9700\u8981\u81ea\u5df1\u8fd0\u884c\u8282\u70b9\u3002\u4e0e\u5176\u76f8\u53cd\uff0c\u53ea\u9700\u91c7\u7528\u4e00\u4e2a\u53cb\u597d\u7684API\uff0cInfura\u5c31\u4f1a\u5b8c\u6210\u6240\u6709\u7e41\u91cd\u7684\u5de5\u4f5c\u3002Infura\u514d\u8d39\u5e76\u4e14\u5b89\u5168\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4f1a\u5b58\u50a8\u7528\u6237\u7684\u79c1\u94a5\uff0c\u4e5f\u65e0\u6cd5\u4fee\u6539\u5176\u4ea4\u6613\u6216\u591a\u6b21\u91cd\u653e\u5b83\u4eec\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u7528\u6237\u53ef\u4ee5\u514d\u8d39\u5f00\u6237\uff0c\u4e0d\u9700\u8981\u91c7\u7528\u4fe1\u7528\u5361\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<h4>\u521b\u5efaInfura\u9879\u76ee<\/h4>\n<p><span style=\"font-size: 13px\">\u521b\u5efa\u9879\u76ee\u662f\u4e8b\u60c5\u53d8\u5f97\u6709\u8da3\u7684\u5730\u65b9\u3002\u6bcf\u4e2a\u9879\u76ee\u90fd\u6709\u4e00\u4e2aAPI\u5bc6\u94a5\uff0c\u7528\u4e8e\u6807\u8bc6\u5b83\u5e76\u5141\u8bb8\u7528\u6237\u4f7f\u7528Infura\uff0c\u7528\u6237\u53ef\u4ee5\u6309\u7167\u8bf4\u660e\u8fdb\u884c\u64cd\u4f5c\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<h4>\u8bbe\u7f6e\u52a0\u5bc6\u94b1\u5305<\/h4>\n<p><span style=\"font-size: 13px\">\u4e0b\u4e00\u4e2a\u96be\u9898\u662f\u8bbe\u7f6e\u52a0\u5bc6\u94b1\u5305\u3002\u5728\u533a\u5757\u94fe\u73af\u5883\u4e2d\uff0c\u52a0\u5bc6\u94b1\u5305\u6301\u6709\u7684\u4f59\u989d\u5b8c\u5168\u7531\u4e00\u7ec4\u6570\u5b57\u5bc6\u94a5\u63a7\u5236\uff0c\u56e0\u6b64\u6ca1\u6709\u6240\u8c13\u7684\u4e2a\u4eba\u8d26\u6237\u6240\u6709\u6743\uff0c\u6bcf\u4e2a\u5e10\u6237\u90fd\u6709\u4e00\u4e2a\u516c\u94a5(\u5728\u533a\u5757\u94fe\u4e2d\u53ef\u89c1)\u548c\u4e00\u4e2a\u63a7\u5236\u8be5\u5e10\u6237\u7684\u79c1\u94a5\u3002\u6301\u6709\u79c1\u94a5\u7684\u7528\u6237\u5b8c\u5168\u63a7\u5236\u4e86\u4e00\u4e2a\u8d26\u6237\u3002\u7528\u6237\u8fd8\u53ef\u4ee5\u5c06\u591a\u4e2a\u5e10\u6237\u4f5c\u4e3a\u4e00\u7ec4\u79c1\u94a5\u8fdb\u884c\u7ba1\u7406\u3002\u52a0\u5bc6\u94b1\u5305\u4e3a\u7528\u6237\u63d0\u4f9b\u4e86\u4e00\u79cd\u5b89\u5168\u7684\u65b9\u5f0f\u6765\u7ba1\u7406\u5176\u5e10\u6237\/\u79c1\u94a5\u4ee5\u53ca\u5176\u4ed6\u597d\u5904\uff0c\u4f8b\u5982\u4fbf\u5229\u6027\u3001\u4fbf\u643a\u6027\u548c\u517c\u5bb9\u6027\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">Infura\u63a8\u8350<\/span><span style=\"font-size: 13px\">\u4f7f\u7528<\/span><span style=\"font-size: 13px\">MetaMask\uff0c\u7528\u6237\u53ef\u4ee5\u5c06MetaMask\u4f5c\u4e3a\u6d4f\u89c8\u5668\u6269\u5c55\u5b89\u88c5\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u5728\u8bbe\u7f6e\u52a0\u5bc6\u94b1\u5305\u4e4b\u540e\uff0c\u53ef\u4ee5\u5f00\u59cb\u8ba8\u8bba\u5982\u4f55\u8d5a\u94b1\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<h4>\u5982\u4f55\u8d5a\u94b1<\/h4>\n<p><span style=\"font-size: 13px\">\u533a\u5757\u94fe\u4e0d\u662f\u514d\u8d39\u4f7f\u7528\u7684\uff0c\u52a0\u5bc6\u8d27\u5e01\u7ecf\u6d4e\u5b66\u9700\u8981\u6295\u5165\u66f4\u591a\u7684\u8d44\u91d1\u3002\u7b80\u5355\u5730\u8bf4\uff0c\u6bcf\u7b14\u4ea4\u6613\u90fd\u8981\u652f\u51fa\u8d39\u7528\u3002\u5982\u679c\u60f3\u5c1d\u8bd5\u533a\u5757\u94fe\u6280\u672f\u5219\u9700\u8981\u6295\u5165\u8d44\u91d1\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u5bf9\u4e8e\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\uff0c\u6709\u4e00\u4e9b\u6d4b\u8bd5\u7f51\u7edc\u53ef\u4ee5\u514d\u8d39\u83b7\u5f97\u6d4b\u8bd5\u8d44\u91d1\uff0c\u867d\u7136\u4e0d\u80fd\u7528\u5b83\u6765\u6362\u53d6\u771f\u5b9e\u7684\u8d27\u5e01\uff0c\u4f46\u662f\u53ef\u4ee5\u7528\u5b83\u6765\u5f00\u53d1\u548c\u6d4b\u8bd5<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u5e94\u7528\u7a0b\u5e8f\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u8bf4\u5230\u8fd9\u4e00\u70b9\uff0c\u6709\u4e0d\u540c\u7c7b\u578b\u7684\u533a\u5757\u94fe\u3002\u5728\u8fd9\u91cc\u5c06\u91cd\u70b9\u5173\u6ce8\u4ee5\u592a\u574a\u533a\u5757\u94fe\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">Alvin<\/span><span style=\"font-size: 13px\"> <\/span><span style=\"font-size: 13px\">Lee<\/span><span style=\"font-size: 13px\">\u5728\u8fd9\u4e2a\u9879\u76ee\u4e2d\u4f7f\u7528\u4e86\u6d4b\u8bd5\u7f51Sepolia\u3002\u4ed6\u53ef\u4ee5\u901a\u8fc7<\/span><span style=\"font-size: 13px\">faucet<\/span><span style=\"font-size: 13px\">\u7ad9\u70b9\u4eceSepolia\u83b7\u5f97\u6d4b\u8bd5ETH(ETH\u662f\u4ee5\u592a\u574a\u7684\u539f\u751f\u52a0\u5bc6\u8d27\u5e01\uff0c\u53ef\u4ee5\u7528\u5b83\u6765\u652f\u4ed8\u4ee5\u592a\u574a\u7f51\u7edc\u4e0a\u7684\u4ea4\u6613\u3002\u800c\u6d4b\u8bd5ETH\u662f\u4ee5\u592a\u574a\u5f00\u53d1\u7684\u5fc5\u8981\u6761\u4ef6) \u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">faucet<\/span><span style=\"font-size: 13px\">\u7ad9\u70b9\u53ef\u4ee5\u5c06\u5c11\u91cf\u7684\u6d4b\u8bd5\u7f51ETH\u8f6c\u79fb\u5230\u52a0\u5bc6\u94b1\u5305\u4e2d\u3002<\/span><span style=\"font-size: 13px\">faucet<\/span><span style=\"font-size: 13px\">\u7ad9\u70b9\u8981\u6c42\u7528\u6237\u6316\u77ff\u6765\u8d5a\u94b1\uff0c\u6709\u4e9b\u4f1a\u5b9a\u671f\u7ed9\u7528\u6237\u4e00\u4e9b\u94b1\u3002<\/span><span style=\"font-size: 13px\">Alvin<\/span><span style=\"font-size: 13px\"> <\/span><span style=\"font-size: 13px\">Lee<\/span><span style=\"font-size: 13px\">\u6210\u529f\u5730\u4f7f\u7528\u4e86ConsenSys Sepolia <\/span><span style=\"font-size: 13px\">faucet<\/span><span style=\"font-size: 13px\">\uff0c\u5b83\u6bcf\u5929\u5411\u4e00\u4e2a\u5730\u5740\u53d1\u90010.5\u4e2aSepolia ETH\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u5728\u4ecb\u7ecd<\/span><span style=\"font-size: 13px\">\u4e86<\/span><span style=\"font-size: 13px\">\u8fd9\u4e9b\u57fa\u7840\u77e5\u8bc6\u4e4b\u540e\uff0c\u4ee5\u4e0b\u4e86\u89e3Infura API\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<h4>\u8bbf\u95eeInfura API<\/h4>\n<p><span style=\"font-size: 13px\">Infura\u901a\u8fc7HTTPS\uff08REST\uff09\u548cWebSockets\u63d0\u4f9b\u4e86\u4e00\u4e2aJSON-RPC API\u3002\u5b83\u6709\u51e0\u4e2a\u7c7b\u522b\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u6587\u7ae0\u4e86\u89e3\u5173\u4e8e\u5b83\u4eec\u7684\u5185\u5bb9\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u6b64\u5916\uff0cInfura API\u652f\u6301\u591a\u79cd\u4e0d\u540c\u7684\u7f51\u7edc\u3002\u6bcf\u4e2a\u7f51\u7edc\u90fd\u6709\u81ea\u5df1\u7684https\u7aef\u70b9\uff0c\u53ef\u4ee5\u5728\u8bbf\u95eeAPI\u65f6\u5c06\u5176\u7528\u4f5c\u57fa\u672cURL\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u4ee5\u4e0b\u662f\u4ee5\u592a\u574a\u7684\u7aef\u70b9\uff1a<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\uff081\uff09<\/span><span style=\"font-size: 13px\">Mainnet<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<ul>\n<li>\u4ee5\u592a\u574a\u4e3b\u7f51JSON-RPC\u57fa\u4e8eHTTPS\u2014https:\/\/mainnet.infura.io\/v3\/&lt;API-KEY&gt; <\/li>\n<li>\u4ee5\u592a\u574a\u4e3b\u7f51JSON-RPC\u57fa\u4e8eWebSocket \u2014 wss:\/\/mainnet.infura.io\/ws\/v3\/&lt;API-KEY&gt;<\/li>\n<\/ul>\n<p><span style=\"font-size: 13px\">\uff082\uff09<\/span><span style=\"font-size: 13px\">Goerli<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<ul>\n<li><span style=\"font-size: 13px\">\u4ee5\u592a\u574aGoerli\u6d4b\u8bd5\u7f51JSON-RPC<\/span><span style=\"font-size: 13px\">\u57fa\u4e8e<\/span><span style=\"font-size: 13px\"> HTTPS<\/span><span style=\"font-size: 13px\">\u2014 <\/span><span style=\"font-size: 13px\">https:\/\/goerli.infura.io\/v3\/&lt;API-KEY&gt;<\/span><span style=\"font-size: 13px\"><\/span><\/li>\n<li><span style=\"font-size: 13px\">\u4ee5\u592a\u574aGoerli\u6d4b\u8bd5\u7f51JSON-RPC\u57fa\u4e8eWebSocket<\/span><span style=\"font-size: 13px\">\u2014wss:\/\/goerli.infura.io\/ws\/v3\/&lt;API-KEY&gt;<\/span><span style=\"font-size: 13px\"><\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: 13px\">\uff083\uff09<\/span><span style=\"font-size: 13px\">Sepolia<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<ul>\n<li><span style=\"font-size: 13px\">\u4ee5\u592a\u574aSepolia\u6d4b\u8bd5\u7f51JSON-RPC <\/span><span style=\"font-size: 13px\">\u57fa\u4e8e<\/span><span style=\"font-size: 13px\">HTTPS<\/span><span style=\"font-size: 13px\">\u2014<\/span><span style=\"font-size: 13px\">https:\/\/sepolia.infura.io\/v3\/&lt;API-KEY&gt;<\/span><span style=\"font-size: 13px\"><\/span><\/li>\n<li><span style=\"font-size: 13px\">\u4ee5\u592a\u574aSepolia\u6d4b\u8bd5\u7f51JSON-RPC<\/span><span style=\"font-size: 13px\">\u57fa\u4e8e<\/span><span style=\"font-size: 13px\">WebSocket<\/span><span style=\"font-size: 13px\">\u2014wss:\/\/sepolia.infura.io\/ws\/v3\/&lt;API-KEY&gt;<\/span><span style=\"font-size: 13px\"><\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: 13px\">\u4e3a\u4e86\u6d4b\u8bd5\u662f\u5426\u53ef\u4ee5\u8bbf\u95eeAPI\uff0c\u53ef\u4ee5\u4f7f\u7528curl\u83b7\u53d6\u94b1\u5305\u4f59\u989d\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u5c06Infura API\u5bc6\u94a5\u548cAPI\u5bc6\u94a5\u79d8\u5bc6\u5b58\u50a8\u5728\u73af\u5883\u53d8\u91cf\u4e2d\uff0c\u7b80\u5355\u5730\u79f0\u4e3a\uff1aINFURA_API_KEY\u548cINFURA_API_KEY_SECRET\u3002\u8fd8\u5c06MetaMask\u94b1\u5305\u7684\u516c\u94a5\u5b58\u50a8\u5728\u4e00\u4e2a\u540d\u4e3aSEPOLIA_ACCOUNT\u7684\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">curl\u547d\u4ee4\u5982\u4e0b:<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>$ curl --user ${INFURA_API_KEY}:${INFURA_API_KEY_SECRET} \\\n -X POST \\\n -H \"Content-Type: application\/json\" \\\n --data '{\"jsonrpc\":\"2.0\",\"method\":\"eth_getBalance\",\"params\":[\"'\"${SEPOLIA_ACCOUNT}\"'\",\"latest\"],\"id\":1}' \\\n https:\/\/sepolia.infura.io\/v3\/${INFURA_API_KEY}\n\na{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x1d7e6e62f1523600\"}<\/code><\/pre>\n<p><span style=\"font-size: 13px\">\u6b63\u5982\u4eba\u4eec\u6240\u89c1\uff0c\u8fd9\u6709\u4e00\u4e2a\u5de8\u5927\u7684\u4f59\u989d<\/span><span style=\"font-size: 13px\">0x1d7e6e62f1523600!!!!<\/span><span style=\"font-size: 13px\">\u4f46\u4e0d\u5fc5\u592a\u5174\u594b\uff0c\u5176\u5e73\u8861\u5355\u4f4d\u662f<\/span><span style=\"font-size: 13px\">Wei<\/span><span style=\"font-size: 13px\">\u3002<\/span><span style=\"font-size: 13px\">1<\/span><span style=\"font-size: 13px\">\u4e2a<\/span><span style=\"font-size: 13px\">ETH<\/span><span style=\"font-size: 13px\">\u7b49\u4e8e<\/span><span style=\"font-size: 13px\">10<\/span><span style=\"font-size: 13px\"><sup>18<\/sup><\/span><span style=\"font-size: 13px\">Wei<\/span><span style=\"font-size: 13px\">\u3002\u5982\u679c\u8ba1\u7b97\u4e00\u4e0b\u6570\u5b57\uff0c\u53ef\u4ee5\u770b\u5230\u8d26\u6237\u91cc\u6709<\/span><span style=\"font-size: 13px\">2<\/span><span style=\"font-size: 13px\">\u4e2a\u591a\u4e00\u70b9\u7684<\/span><span style=\"font-size: 13px\">ETH<\/span><span style=\"font-size: 13px\">\u3002\u5f53\u7136\uff0c\u8fd9\u90fd\u662f\u6d4b\u8bd5\u7f51\u7edc\u7684\u94b1\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u8fd9\u91cc\u4e0d\u9700\u8981\u4f7f\u7528\u5e10\u6237\u79c1\u94a5\u6765\u68c0\u67e5\u4f59\u989d\u3002\u4efb\u4f55\u4eba\u90fd\u53ef\u4ee5\u67e5\u770b\u533a\u5757\u94fe\u4e2d\u4efb\u4f55\u8d26\u6237\u7684\u4f59\u989d\uff0c\u800c\u5e10\u6237\u4f59\u989d\u5e76\u4e0d\u662f\u654f\u611f\u4fe1\u606f\u3002\u4f46\u662f\uff0c\u5e10\u6237\u548c\u6301\u6709\u79c1\u94a5\u7684\u4eba\u7684\u8eab\u4efd\u662f\u654f\u611f\u548c\u673a\u5bc6\u7684\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u5728\u76f4\u63a5\u8bbf\u95eeInfura API\u65f6\u6709\u7740\u5f88\u597d\u7684\u4f53\u9a8c\uff0c\u63a5\u4e0b\u6765\u9700\u8981\u7f16\u5199\u4e00\u4e9b\u4ee3\u7801\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<h4>\u91c7\u7528Python\u5f00\u53d1Web3<\/h4>\n<p><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u751f\u6001\u7cfb\u7edf\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002\u53ef\u4ee5\u4eceJavaScript\uff08web3.js\u548cethers.js\uff09\u3001Golang\u548cPython\uff08web3.py\uff09\u4e2d\u7684\u6d41\u884c\u5e93\u8bbf\u95eeInfura API\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<h4>\u9009\u62e9\u5de5\u5177\uff1aweb3.py<\/h4>\n<p><span style=\"font-size: 13px\">\u867d\u7136\u73b0\u5728\u5927\u591a\u6570\u4ee3\u7801\u90fd\u662f\u7528JavaScript\/Node.js\u548cRuby\u7f16\u5199\u7684\uff0c\u4f46\u5728\u5b66\u4e60\u65b0\u4e3b\u9898\u65f6\uff0cPython\u662f\u5f88\u597d\u7684\u9009\u62e9\u3002web3.py\u5e93\u770b\u8d77\u6765\u529f\u80fd\u5f3a\u5927\u3001\u6210\u719f\u4e14\u6587\u6863\u9f50\u5168\u3002\u6240\u4ee5<\/span><span style=\"font-size: 13px\">Alvin<\/span><span style=\"font-size: 13px\"> <\/span><span style=\"font-size: 13px\">Lee<\/span><span style=\"font-size: 13px\">\u51b3\u5b9a\u9009\u62e9web3.py\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<h4>\u9009\u62e9\u76ee\u6807\uff1a\u52a0\u5bc6\u94b1\u5305\u7ba1\u7406\u5668<\/h4>\n<p><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u7684\u4e16\u754c\u53ef\u80fd\u662f\u538b\u5012\u6027\u7684\uff1a\u4ea4\u6613\u3001\u667a\u80fd\u5408\u7ea6\u3001IPFS\u3001DAO(\u53bb\u4e2d\u5fc3\u5316\u81ea\u6cbb\u7ec4\u7ec7)\u3001<\/span><span style=\"font-size: 13px\">D<\/span><span style=\"font-size: 13px\">e<\/span><span style=\"font-size: 13px\">F<\/span><span style=\"font-size: 13px\">i(\u53bb\u4e2d\u5fc3\u5316\u91d1\u878d)\u548cNFT\u3002<\/span><span style=\"font-size: 13px\">Alvin<\/span><span style=\"font-size: 13px\"> <\/span><span style=\"font-size: 13px\">Lee<\/span><span style=\"font-size: 13px\">\u51b3\u5b9a\u4e3a\u8fd9\u4e2a<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u6d4b\u8bd5\u9879\u76ee\u9009\u62e9\u4e00\u4e2a\u7b80\u5355\u7684\u52a0\u5bc6\u94b1\u5305\u7ba1\u7406\u5668\u6982\u5ff5\u3002\u52a0\u5bc6\u94b1\u5305\u7ba1\u7406\u5668\u662f\u4e00\u79cd\u201chello web3 world\u201d\u9879\u76ee\uff0c\u56e0\u4e3a\u5b83\u6240\u505a\u7684\u5c31\u662f\u83b7\u53d6\u4f59\u989d\u5e76\u5c06\u4e00\u4e9b\u94b1\u53d1\u9001\u5230\u76ee\u6807\u8d26\u6237\u3002\u81ea\u4ece<\/span><span style=\"font-size: 13px\">Alvin<\/span><span style=\"font-size: 13px\"> <\/span><span style=\"font-size: 13px\">Lee<\/span><span style=\"font-size: 13px\">\u91c7\u7528Sepolia<\/span><span style=\"font-size: 13px\"> faucet<\/span><span style=\"font-size: 13px\">\u8d5a\u94b1\u4ee5\u6765\uff0c\u4ed6\u51b3\u5b9a\u53d1\u9001\u4e00\u4e9b\u8d44\u91d1\u6765\u56de\u9988\u5b83\u3002\u5148\u68c0\u67e5\u4e00\u4e0b\u4ee3\u7801\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<h4>web3-test dApp(\u53bb\u4e2d\u5fc3\u5316\u5e94\u7528)<\/h4>\n<p><span style=\"font-size: 13px\">\u8fd9\u4e9b\u4ee3\u7801\u53ef\u4ee5\u5728Github\u4e0a\u627e\u5230\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u4f7f\u7528Poetry\u6765\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u81ea\u8ff0\u6587\u4ef6\u63d0\u4f9b\u4e86\u4e00\u6b65\u4e00\u6b65\u7684\u8bbe\u7f6e\u8bf4\u660e\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u5728\u6df1\u5165\u7814\u7a76\u4ee3\u7801\u4e4b\u524d\uff0c\u5148\u8fd0\u884c\u4e00\u4e0b\u7a0b\u5e8f\uff0c\u770b\u770b\u4f1a\u53d1\u751f\u4ec0\u4e48:<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>$ poetry run python main.py\n\nbalance before transaction: 2.1252574454\nsend 20,000 gwei to 0xea4d57b2dd421c5bfc893d126ec15bc42b3d0bcd (Sepolia faucet account)\nbalance after transaction: 2.125184945399832<\/code><\/pre>\n<p><span style=\"font-size: 13px\">\u6b63\u5982\u4eba\u4eec\u6240\u770b\u5230\u7684\u90a3\u6837\uff0c<\/span><span style=\"font-size: 13px\">Alvin<\/span><span style=\"font-size: 13px\"> <\/span><span style=\"font-size: 13px\">Lee<\/span><span style=\"font-size: 13px\">\u7684\u4f59\u989d\u6700\u521d\u662f\u7565\u9ad8\u4e8e2\u4e2atestnet ETH\u3002\u7136\u540e\uff0c\u5c0620,000 Gwei(\u5373200\u4ebfWei)\u53d1\u9001\u5230\u6700\u521d\u83b7\u5f97\u8d44\u91d1\u7684Sepolia<\/span><span style=\"font-size: 13px\"> faucet<\/span><span style=\"font-size: 13px\">\u8d26\u6237\u3002\u5b83\u51e0\u4e4e\u6ca1\u6709\u5f71\u54cd\u8d44\u91d1\u5e73\u8861\u3002\u8fd9\u6b63\u597d\u8bf4\u660eWei\u662f\u4e00\u4e2a\u591a\u4e48\u5c0f\u7684\u5355\u4f4d\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u8fd9\u4e2a\u4ee3\u7801\u975e\u5e38\u7b80\u5355\u3002\u53ea\u6709\u4e00\u4e2a\u540d\u4e3amain.py\u7684\u6587\u4ef6\u3002\u8be5\u6587\u4ef6\u5305\u542b\u4e00\u4e2amain()\u51fd\u6570\u548c\u4e00\u4e2aWalletManager\u7c7b\u3002\u5148\u4ecemain()\u51fd\u6570\u5f00\u59cb\uff0c\u5b83\u662f\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">main()\u51fd\u6570\u4e0d\u63a5\u53d7\u547d\u4ee4\u884c\u53c2\u6570\u6216\u914d\u7f6e\u6587\u4ef6\u3002\u4e00\u5207\u90fd\u662f\u4e3a\u4e86\u7b80\u5355\u800c\u786c\u7f16\u7801\u7684\u3002\u9996\u5148\uff0c\u8be5\u51fd\u6570\u5b9e\u4f8b\u5316WalletManager\u7c7b\uff0c\u7136\u540e\u5b9a\u4e49Sepolia <\/span><span style=\"font-size: 13px\">faucet<\/span><span style=\"font-size: 13px\">\u5e10\u6237\u7684\u516c\u94a5\u3002\u73b0\u5728\u5f00\u59cb\u884c\u52a8\u3002\u8be5\u51fd\u6570\u901a\u8fc7\u8c03\u7528WalletManager\u7684get_balance()\u65b9\u6cd5\u83b7\u5f97\u52a0\u5bc6\u94b1\u5305\u7684\u4f59\u989d\uff0c\u7136\u540e\u4f20\u9012\u6240\u8bf7\u6c42\u7684\u5355\u4f4d(\u4ee5\u592a\u5e01)\uff0c\u5e76\u5c06\u5176\u663e\u793a\u5728\u5c4f\u5e55\u4e0a\u3002\u63a5\u4e0b\u6765\uff0c\u8be5\u51fd\u6570\u8c03\u7528send_eth()\u65b9\u6cd5\u5c0620,000 Gwei\u53d1\u9001\u5230\u76ee\u6807\u5e10\u6237\u3002\u6700\u540e\uff0c\u5b83\u5728\u6c47\u6b3e\u540e\u518d\u6b21\u83b7\u53d6\u5e76\u663e\u793a\u4f59\u989d\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>def main():\n wm = WalletManager()\n\n sepolia_faucet_account = wm.w3.toChecksumAddress('0xea4d57b2dd421c5bfc893d126ec15bc42b3d0bcd')\n\n balance = str(wm.get_balance('ether'))\n print(f'balance before transaction: {balance}')\n\n print(f'send 20,000 gwei to {sepolia_faucet_account} (Sepolia faucet account)')\n wm.send_eth(sepolia_faucet_account, 20000, 'gwei')\n\n balance = str(wm.get_balance('ether'))\n print(f'balance after transaction: {balance}')\n\nif __name__ == '__main__':\n main()<\/code><\/pre>\n<p><span style=\"font-size: 13px\">\u7136\u540e\u770b\u4e00\u4e0bWalletManager\u7c7b\u3002\u5b83\u6709\u56db\u79cd\u65b9\u6cd5\uff1a<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>\u00b7__init__(),\n\u00b7__create_web3_instance()\n\u00b7get_balance()\n\u00b7sent_eth()<\/code><\/pre>\n<h4>\u65b9\u6cd51\uff1a__init__()<\/h4>\n<p><span style=\"font-size: 13px\">\u4ee5\u4e0b\u9010\u4e00\u8fdb\u884c\u4e86\u89e3\u3002__init__()\u65b9\u6cd5\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\uff0c\u5b83\u9996\u5148\u8c03\u7528__create_web3_instance()\u65b9\u6cd5\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728\u4e00\u4e2a\u540d\u4e3aw3\u7684\u53d8\u91cf\u4e2d\u3002\u7136\u540e__init__()\u63d0\u53d6\u51e0\u4e2a\u73af\u5883\u53d8\u91cf\u5e76\u5b58\u50a8\u5b83\u4eec\u3002\u5b83\u7ee7\u7eed\u8ba1\u7b97\u4e00\u4e9bGas\u8d39\u7528(Gas\u662f\u533a\u5757\u94fe\u8fd0\u884c\u7684\u71c3\u6599)\u548c\u7ed9\u9a8c\u8bc1\u4ea4\u6613\u7684\u4eba\u5458\u7684\u5956\u52b1\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u5b83\u8fd8\u5b58\u50a8\u94feID\uff0c\u7528\u4e8e\u6807\u8bc6Sepolia\u6d4b\u8bd5\u7f51(\u5728\u672c\u4f8b\u4e2d)\u3002\u7a0d\u540e\u5728\u5411Sepolia\u6d4b\u8bd5\u7f51\u53d1\u9001\u4ea4\u6613\u65f6\uff0c\u5c06\u9700\u8981\u8fd9\u4e2aID\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>Import base64\nimport os\nimport web3\n\nclass WalletManager:\n def __init__(self):\n self.w3 = self.__create_web3_instance()\n self.account = os.environ[\u2018SEPOLIA_ACCOUNT\u2019]\n self.account_private_key = os.environ[\u2018METAMASK_PRIVATE_KEY\u2019]\n self.max_fee_per_gas = self.w3.toWei(\u2018250\u2019, \u2018gwei\u2019)\n self.max_priority_fee_per_gas = self.w3.eth.max_priority_fee\n self.chain_id = self.w3.eth.chain_id<\/code><\/pre>\n<h4>\u65b9\u6cd52\uff1a__create_web3_instance()<\/h4>\n<p><span style=\"font-size: 13px\">\u53ef\u4ee5\u4e86\u89e3__create_web3_instance()\u65b9\u6cd5\u5185\u90e8\u53d1\u751f\u4e86\u4ec0\u4e48\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">__create_web3_instance()\u662f\u4e00\u4e2a\u9759\u6001\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u4e0d\u9700\u8981\u6765\u81eaWalletManager\u7c7b\u7684\u4efb\u4f55\u4fe1\u606f\u3002\u5b83\u4ece\u73af\u5883\u4e2d\u83b7\u53d6Infura API\u5bc6\u94a5\u548cAPI\u5bc6\u94a5\u79d8\u5bc6\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u7f16\u7801\u4e3a\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\u3002\u5b83\u5728Sepolia\u6d4b\u8bd5\u7f51\u4e0a\u4e3a\u9879\u76ee\u51c6\u5907\u4e86\u9002\u5f53\u7684\u7aef\u70b9\uff0c\u7136\u540e\u7528\u6240\u6709\u4fe1\u606f\u5b9e\u4f8b\u5316\u4e86<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u5e93\u4e2d\u7684\u4e00\u4e2a<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u5bf9\u8c61\u3002\u8fd9\u4e2a\u5bf9\u8c61\u5c06\u5141\u8bb8\u901a\u8fc7\u4e00\u4e2a\u65b9\u4fbf\u7684Python\u63a5\u53e3\u8c03\u7528Infura API(\u800c\u4e0d\u662f\u6784\u9020JSON-RPC\u8bf7\u6c42\u5e76\u89e3\u6790\u7ed3\u679c)\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>@staticmethod\ndef __create_web3_instance():\n infura_api_key = os.environ['INFURA_API_KEY']\n infura_api_key_secret = os.environ['INFURA_API_KEY_SECRET']\n data = f'{infura_api_key}:{infura_api_key_secret}'.encode('ascii')\n basic_auth_token = base64.b64encode(data).strip().decode('utf-8')\n\n infura_sepolia_endpoint = f'https:\/\/sepolia.infura.io\/v3\/{infura_api_key}'\n\n headers = dict(Authorization=f'Basic {basic_auth_token}')\n return web3.Web3(web3.HTTPProvider(infura_sepolia_endpoint, request_kwargs=dict(headers=headers)))<\/code><\/pre>\n<h4>\u65b9\u6cd53\uff1aget_balance()<\/h4>\n<p><span style=\"font-size: 13px\">\u4e0b\u4e00\u4e2a\u662fget_balance()\u65b9\u6cd5\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u8fd9\u662f\u4e00\u79cd\u6781\u5176\u7b80\u5355\u7684\u65b9\u6cd5\u3002\u5b83\u53ea\u8c03\u7528<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u5bf9\u8c61\u7684w3.eth.get_balance()\u65b9\u6cd5\u5e76\u4f20\u9012\u5e10\u6237\u3002eth.get_balance()\u603b\u662f\u8fd4\u56deWei\u7684\u7ed3\u679c\uff0cWei\u901a\u5e38\u592a\u5c0f\u3002\u800c\u8fd9\u79cd\u65b9\u6cd5\u63d0\u4f9b\u4e86\u5c06\u7ed3\u679c\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u9762\u989d(\u4f8b\u5982Gwei\u6216Ether)\u7684\u9009\u9879\u3002\u5b83\u901a\u8fc7\u8c03\u7528<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u5b9e\u4f8b\u518d\u6b21\u63d0\u4f9b\u7684w3.fromWei()\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u9700\u8981\u6ce8\u610f\u7684<\/span><span style=\"font-size: 13px\">\u662f<\/span><span style=\"font-size: 13px\">\uff0c\u4e0d\u5fc5\u4f7f\u7528\u79c1\u94a5\u6765\u68c0\u67e5\u4f59\u989d\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>balance = self.w3.eth.get_balance(selpytf.account)\nif unit != 'wei':\n return self.w3.fromWei(balance, unit)<\/code><\/pre>\n<h4>\u65b9\u6cd54\uff1asend_eth()<\/h4>\n<p><span style=\"font-size: 13px\">\u6700\u540e\u4f46\u540c\u6837\u91cd\u8981\u7684\u662fsend_eth()\u65b9\u6cd5\u3002\u8fd9\u91cc\u6709\u5f88\u591a\u5185\u5bb9\uff0c\u6240\u4ee5\u53ef\u4ee5\u5c06\u5176\u5206\u6210\u591a\u4e2a\u5757\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\">\u9996\u5148\uff0csend_eth()\u8f6c\u6362\u8981\u53d1\u9001\u7ed9Wei\u7684\u91d1\u989d(\u5982\u679c\u9700\u8981)\uff0c\u7136\u540e\u5b83\u83b7\u53d6\u8be5\u5e10\u6237\u7684\u4ea4\u6613\u8ba1\u6570\u5e76\u5c06\u5176\u5b58\u50a8\u4e3anonce\u3002nonce\u5141\u8bb8\u5728\u9700\u8981\u65f6\u8986\u76d6\u6302\u8d77\u7684\u4ea4\u6613\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>def send_eth(self, target_account, amount, unit='wei'):\n if unit != 'wei':\n amount = self.w3.toWei(amount, unit)\n\n nonce = self.w3.eth.get_transaction_count(self.account)<\/code><\/pre>\n<p><span style=\"font-size: 13px\">\u63a5\u4e0b\u6765\uff0c\u5b83\u6784\u9020\u4e00\u4e2a\u4ea4\u6613\u5bf9\u8c61\u3002\u6700\u91cd\u8981\u7684\u5b57\u6bb5\u662ffrom(\u52a0\u5bc6\u94b1\u5305\u7684\u8d26\u6237)\u3001to(\u4ea4\u6613\u7684\u63a5\u6536\u8005)\u548cvalue(\u8981\u53d1\u9001\u591a\u5c11\u94b1)\u3002\u7136\u540e\uff0c\u8fd8<\/span><span style=\"font-size: 13px\">\u8981<\/span><span style=\"font-size: 13px\">\u51b3\u5b9a\u652f\u4ed8\u591a\u5c11Gas\uff0cGas\u8d8a\u591a\uff0c\u9a8c\u8bc1\u5668\u5305\u542b\u4ea4\u6613\u7684\u53ef\u80fd\u6027\u5c31\u8d8a\u5927\u3002chainId\u6807\u8bc6\u8fd0\u884c\u8fd9\u4e00\u4ea4\u6613\u7684\u7f51\u7edc\u548c\u51e0\u4e2a\u7ba1\u7406\u5b57\u6bb5(\u7a7a\u6570\u636e\u548c\u7c7b\u578b)\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>tx = {'nonce': nonce,\n 'maxFeePerGas': self.max_fee_per_gas,\n 'maxPriorityFeePerGas': self.max_priority_fee_per_gas,\n 'from': self.account,\n 'to': target_account,\n 'value': amount,\n 'data': b'',\n 'type': 2,\n 'chainId': self.chain_id}\ntx['gas'] = self.w3.eth.estimate_gas(tx)<\/code><\/pre>\n<p><span style=\"font-size: 13px\">\u8fd9\u91cc\u6709\u4e00\u7b14\u4ea4\u6613\uff0c\u53ef\u4ee5\u53d1\u9001\u5417?\u5148\u4e0d\u8981\u8fd9\u4e48\u5feb\u53d1\u9001\u3002\u9996\u5148\uff0c\u9700\u8981\u91c7\u7528\u79c1\u94a5\u7b7e\u540d\u3002\u8fd9\u662f\u9632\u6b62\u5176\u4ed6\u4eba\u4ece\u7528\u6237\u7684\u8d26\u6237\u8f6c\u8d26\u7684\u539f\u56e0\u3002\u4f7f\u7528\u79c1\u94a5\u7b7e\u7f72\u4ea4\u6613\u5141\u8bb8\u9a8c\u8bc1\u5668\u786e\u8ba4\u79c1\u94a5\u4e0e\u5e10\u6237\u7684\u516c\u94a5\u76f8\u5bf9\u5e94\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>signed_tx = self.w3.eth.account.sign_transaction(tx, self.account_private_key)<\/code><\/pre>\n<p><span style=\"font-size: 13px\">\u73b0\u5728\u53ef\u4ee5\u5c06\u4ea4\u6613\u4f5c\u4e3a\u539f\u59cb\u4ea4\u6613\u53d1\u9001\u3002\u8fd9\u610f\u5473\u7740Infura\u6c38\u8fdc\u4e0d\u4f1a\u770b\u5230\u7528\u6237\u7684\u79c1\u94a5\uff0c\u5b83\u4e0d\u80fd\u6539\u53d8\u4ea4\u6613\u6216\u5c06\u5176\u8f6c\u8d26\u5230\u53e6\u4e00\u4e2a\u8d26\u6237\u3002\u8fd9\u5c31\u662f\u533a\u5757\u94fe\u7684\u9b54\u529b\u3002\u5728\u53d1\u9001\u4ea4\u6613\u540e\uff0c\u8fd4\u56de\u4e00\u4e2a\u54c8\u5e0c\u7801\u5e76\u7b49\u5f85\u4ea4\u6613\u5b8c\u6210\u3002\u5982\u679c\u7ed3\u679c\u7684\u72b6\u6001\u4e3a1\uff0c\u5219\u4e00\u5207\u6b63\u5e38\u3002\u5982\u679c\u4e0d\u662f\uff0c\u4ee3\u7801\u5c06\u5f15\u53d1\u5f02\u5e38\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<pre><code>tx_hash = self.w3.eth.send_raw_transaction(signed_tx.rawTransaction)\n\nresult = self.w3.eth.wait_for_transaction_receipt(tx_hash)\nif result['status'] != 1:\n raise RuntimeError('transaction failed: {tx_hash}')<\/code><\/pre>\n<p><span style=\"font-size: 13px\">\u8fd9\u5c31\u662f\u4ee5\u4e00\u79cd\u975e\u5e38\u57fa\u672c\u4f46\u5b89\u5168\u7684\u65b9\u5f0f\u4e0e\u533a\u5757\u94fe\u4ea4\u4e92\u6240\u9700\u8981\u7684\u5168\u90e8\u5185\u5bb9\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<h4>\u7ed3\u8bba\uff1a\u7528Infura\u5f00\u59cbWeb3\u4e4b\u65c5<\/h4>\n<p><span style=\"font-size: 13px\">\u5373\u4f7f\u5bf9\u4e8e\u4e00\u540d\u7ecf\u9a8c\u4e30\u5bcc\u7684\u7a0b\u5e8f\u5458\u6765\u8bf4\uff0c\u4ece\u5934\u5f00\u59cb\u8fdb\u5165<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3<\/span><span style=\"font-size: 13px\">\u7684\u4e16\u754c\u4e5f\u53ef\u80fd\u4ee4\u4eba\u671b\u800c\u751f\u754f\u3002\u800c\u5728\u9010\u6b65\u7684\u5b66\u4e60\u4e2d\u5b66\u5230\u4e86\u5f88\u591a\u6280\u5de7\u3002\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4eba\u4eec\u77e5\u9053\u81ea\u5df1\u8fd8\u6709\u5f88\u591a\u5185\u5bb9\u8981\u5b66\u3002Infura\u901a\u8fc7\u63d0\u4f9b\u53ef\u9760\u7684API\u3001\u51fa\u8272\u7684\u6307\u5bfc\u4ee5\u53ca\u4e0e\u751f\u6001\u7cfb\u7edf\u7684\u5176\u4ed6\u7ec4\u4ef6(\u4f8b\u5982MetaMask\u548cweb3.py\u5e93)\u7684\u5f3a\u5927\u96c6\u6210\uff0c\u4f7f\u5176\u53d8\u5f97\u7b80\u5355\u3002\u5982\u679c\u4eba\u4eec\u5904\u4e8e\u7c7b\u4f3c\u7684\u4f4d\u7f6e\uff0c\u5e0c\u671b\u5b66\u4e60<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u5f00\u53d1\uff0c\u6216\u8005\u751a\u81f3\u60f3\u8981\u5f00\u59cb<\/span><span style=\"font-size: 13px\">W<\/span><span style=\"font-size: 13px\">eb3\u7684\u804c\u4e1a\u751f\u6daf\uff0c\u90a3\u4e48\u5f3a\u70c8\u5efa\u8bae\u4eceInfura\u5f00\u59cb\u3002<\/span><span style=\"font-size: 13px\"><\/span><\/p>\n<p><span style=\"font-size: 13px\"><strong>\u539f\u6587\u6807\u9898\uff1a<\/strong><\/span><span style=\"font-size: 13px\"><strong>From Zero to Hero: Learning Web3 With Infura and Python<\/strong><\/span><span style=\"font-size: 13px\"><strong>\uff0c<\/strong><\/span><span style=\"font-size: 13px\"><strong>\u4f5c\u8005\uff1aAlvin Lee<\/strong><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bd1\u8005 | \u674e\u777f \u5ba1\u6821 | \u91cd\u697c Web3\u3001\u533a\u5757\u94fe\u6280\u672f\u548c\u52a0\u5bc6\u8d27\u5e01\u5982\u4eca\u90fd\u662f\u4ee4\u4eba\u5173\u6ce8\u7684\u70ed\u95e8\u8bdd\u9898\u3002\u6280\u672f\u3001\u5e94\u7528\u3001\u751f\u6001\u7cfb\u7edf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":244730,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[200988],"tags":[],"class_list":["post-244729","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-200988"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/244729","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=244729"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/244729\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/244730"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=244729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=244729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=244729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}