{"id":47435,"date":"2024-12-02T11:40:34","date_gmt":"2024-12-02T03:40:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47435\/"},"modified":"2024-12-02T11:40:34","modified_gmt":"2024-12-02T03:40:34","slug":"php-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e6%89%a9%e5%b1%95%e5%88%b0%e5%9d%97%e9%93%be%e6%8a%80%e6%9c%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47435\/","title":{"rendered":"PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5757\u94fe\u6280\u672f\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5757\u94fe\u6280\u672f\uff1f<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aPHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5757\u94fe\u6280\u672f\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p>PHP \u51fd\u6570\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 Web3.php \u5e93\u6269\u5c55\u5230\u533a\u5757\u94fe\u6280\u672f\u3002\u901a\u8fc7\u8be5\u5e93\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u4e0e\u533a\u5757\u94fe\u4ea4\u4e92\uff0c\u5305\u62ec\u83b7\u53d6\u5757\u53f7\u3001\u53d1\u9001\u4ea4\u6613\u548c\u83b7\u53d6\u4ea4\u6613\u54c8\u5e0c\u503c\u3002\u6b64\u5916\uff0cPHP \u51fd\u6570\u8fd8\u53ef\u4e0e\u667a\u80fd\u5408\u7ea6\u4ea4\u4e92\uff0c\u4f8b\u5982\u8c03\u7528\u51fd\u6570\u548c\u68c0\u7d22\u6570\u636e\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528 PHP \u51fd\u6570\u4ece\u4ee5\u592a\u574a\u533a\u5757\u94fe\u68c0\u7d22 ETH \u4f59\u989d\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729917974671c7416b149f.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5757\u94fe\u6280\u672f\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5757\u94fe\u6280\u672f\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u533a\u5757\u94fe\u6280\u672f<\/h2>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u533a\u5757\u94fe\u6280\u672f\u6b63\u5728\u8fc5\u901f\u5d1b\u8d77\uff0c\u4e3a\u5404\u79cd\u884c\u4e1a\u63d0\u4f9b\u4e86\u65b0\u7684\u53ef\u80fd\u6027\u3002\u4e3a\u4e86\u5229\u7528\u533a\u5757\u94fe\u7684\u4f18\u52bf\uff0cPHP \u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u4f7f\u7528\u6269\u5c55\u5757\u94fe\u7684\u73b0\u6709\u51fd\u6570\u3002\u672c\u6587\u5c06\u5411\u60a8\u5c55\u793a\u5982\u4f55\u901a\u8fc7\u5b9e\u9645\u6848\u4f8b\u6269\u5c55 PHP \u51fd\u6570\u4ee5\u4e0e\u533a\u5757\u94fe\u4ea4\u4e92\u3002<\/p>\n<p><strong>\u4f7f\u7528 Web3.php \u5e93<\/strong><\/p>\n<p>Web3.php \u662f\u4e00\u4e2a\u6d41\u884c\u7684 PHP \u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e0e\u4ee5\u592a\u574a\u533a\u5757\u94fe\u4ea4\u4e92\u7684\u63a5\u53e3\u3002\u5b89\u88c5\u6b64\u5e93\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u4e0e\u533a\u5757\u94fe\u8fdb\u884c\u4ea4\u4e92\uff1a<\/p>\n<pre>use Web3\\Web3;\n\n$web3 = new Web3('http:\/\/localhost:8545');\n\n\/\/ \u83b7\u53d6\u4ee5\u592a\u574a\u533a\u5757\u94fe\u7684\u5f53\u524d\u5757\u53f7\n$blockNumber = $web3-&gt;eth-&gt;blockNumber();\n\n\/\/ \u5728\u4ee5\u592a\u574a\u533a\u5757\u94fe\u4e0a\u53d1\u9001\u4ea4\u6613\n$transaction = $web3-&gt;eth-&gt;sendTransaction([\n    'from' =&gt; '0x0000000000000000000000000000000000000000',\n    'to' =&gt; '0x1111111111111111111111111111111111111111',\n    'value' =&gt; '1000000000000000000'\n]);\n\n\/\/ \u83b7\u53d6\u4ea4\u6613\u7684\u54c8\u5e0c\u503c\n$transactionHash = $transaction-&gt;hash();<\/pre>\n<p><strong>\u4e0e\u667a\u80fd\u5408\u7ea6\u4ea4\u4e92<\/strong><\/p>\n<p>\u9664\u4e86\u4e0e\u533a\u5757\u94fe\u672c\u8eab\u4ea4\u4e92\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528 PHP \u51fd\u6570\u4e0e\u667a\u80fd\u5408\u7ea6\u4ea4\u4e92\u3002\u4e3a\u6b64\uff0c\u60a8\u9700\u8981\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u52a0\u8f7d\u5df2\u90e8\u7f72\u7684\u667a\u80fd\u5408\u7ea6\uff1a<\/p>\n<pre>use Web3\\Contract;\n\n$contract = $web3-&gt;contract([\n    'address' =&gt; '0x1234567890123456789012345678901234567890',\n    'abi' =&gt; json_decode($contractABI)\n]);\n\n\/\/ \u8c03\u7528\u667a\u80fd\u5408\u7ea6\u51fd\u6570\n$result = $contract-&gt;call('myFunction', ['param1', 'param2']);<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 PHP \u51fd\u6570\u4ece\u4ee5\u592a\u574a\u533a\u5757\u94fe\u68c0\u7d22 ETH \u4f59\u989d\u7684\u5b9e\u9645\u6848\u4f8b\uff1a<\/p>\n<pre>use Web3\\Web3;\n\n$web3 = new Web3('http:\/\/localhost:8545');\n\n$address = '0x0000000000000000000000000000000000000000';\n$balance = $web3-&gt;eth-&gt;getBalance($address);\n\necho $balance;<\/pre>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u4f7f\u7528\u6269\u5c55\u5757\u94fe\u7684 PHP \u51fd\u6570\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5229\u7528\u533a\u5757\u94fe\u6280\u672f\u7684\u5f3a\u5927\u529f\u80fd\u6765\u521b\u5efa\u521b\u65b0\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u901a\u8fc7\u4f7f\u7528 Web3.php \u7b49\u5e93\u548c\u672c\u6587\u4e2d\u6982\u8ff0\u7684\u6280\u672f\uff0c\u60a8\u53ef\u4ee5\u4e0e\u533a\u5757\u94fe\u4ea4\u4e92\uff0c\u4e0e\u667a\u80fd\u5408\u7ea6\u4ea4\u4e92\uff0c\u5e76\u6784\u5efa\u5404\u79cd\u4ee5\u533a\u5757\u94fe\u4e3a\u4e2d\u5fc3\u7684\u9879\u76ee\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5757\u94fe\u6280\u672f\uff1f \u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aPHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u5757\u94fe\u6280\u672f\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 PHP \u51fd\u6570\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 Web3.php \u5e93\u6269\u5c55\u5230\u533a\u5757\u94fe\u6280\u672f\u3002\u901a\u8fc7\u8be5\u5e93\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u4e0e\u533a\u5757\u94fe\u4ea4\u4e92\uff0c\u5305\u62ec\u83b7\u53d6\u5757\u53f7\u3001\u53d1\u9001\u4ea4\u6613\u548c\u83b7\u53d6\u4ea4\u6613\u54c8\u5e0c\u503c\u3002\u6b64\u5916\uff0cPHP \u51fd\u6570\u8fd8\u53ef\u4e0e\u667a\u80fd\u5408\u7ea6\u4ea4\u4e92\uff0c\u4f8b\u5982\u8c03\u7528\u51fd\u6570\u548c\u68c0\u7d22\u6570\u636e\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528 PHP \u51fd\u6570\u4ece\u4ee5\u592a\u574a\u533a\u5757\u94fe\u68c0\u7d22 ETH \u4f59\u989d\u3002 PHP \u51fd\u6570\u5982\u4f55\u6269\u5c55\u5230\u533a\u5757\u94fe\u6280\u672f \u5f15\u8a00 \u533a\u5757\u94fe\u6280\u672f\u6b63\u5728\u8fc5\u901f\u5d1b\u8d77\uff0c\u4e3a\u5404\u79cd\u884c\u4e1a\u63d0\u4f9b\u4e86\u65b0\u7684\u53ef\u80fd\u6027\u3002\u4e3a\u4e86\u5229\u7528\u533a\u5757\u94fe\u7684\u4f18\u52bf\uff0cPHP \u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u4f7f\u7528\u6269\u5c55\u5757\u94fe\u7684\u73b0\u6709\u51fd\u6570\u3002\u672c\u6587\u5c06\u5411\u60a8\u5c55\u793a\u5982\u4f55\u901a\u8fc7\u5b9e\u9645\u6848\u4f8b\u6269\u5c55 PHP \u51fd\u6570\u4ee5\u4e0e\u533a\u5757\u94fe\u4ea4\u4e92\u3002 \u4f7f\u7528 Web3.php \u5e93 Web3.php \u662f\u4e00\u4e2a\u6d41\u884c\u7684 PHP \u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e0e\u4ee5\u592a\u574a\u533a\u5757\u94fe\u4ea4\u4e92\u7684\u63a5\u53e3\u3002\u5b89\u88c5\u6b64\u5e93\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u4e0e\u533a\u5757\u94fe\u8fdb\u884c\u4ea4\u4e92\uff1a use Web3\\Web3; $web3 = new Web3(&#8216;http:\/\/localhost:8545&#8217;); \/\/ \u83b7\u53d6\u4ee5\u592a\u574a\u533a\u5757\u94fe\u7684\u5f53\u524d\u5757\u53f7 $blockNumber = $web3-&gt;eth-&gt;blockNumber(); \/\/ \u5728\u4ee5\u592a\u574a\u533a\u5757\u94fe\u4e0a\u53d1\u9001\u4ea4\u6613 $transaction = $web3-&gt;eth-&gt;sendTransaction([ &#8216;from&#8217; =&gt; &#8216;0x0000000000000000000000000000000000000000&#8217;, &#8216;to&#8217; =&gt; &#8216;0x1111111111111111111111111111111111111111&#8217;, &#8216;value&#8217; =&gt; &#8216;1000000000000000000&#8217; ]); \/\/ \u83b7\u53d6\u4ea4\u6613\u7684\u54c8\u5e0c\u503c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-47435","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=47435"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47435\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}