20 交易哈希怎么用PHP实现web3读取logs里面的信息,并且解码内容

web3.js 前端单独研究了下,可以解码出来,用到这几个方法 encodeEventSignature,getTransactionReceipt,decodeLog

就是 php 后端不晓得怎么实现,主要有些库可能没这个方法 decodeLog,也许是我不会用。

IDE上链的时候打印内容是这样:

logs
[
    {
        "from": "0x7bd38c5056234e91A2C9C11960007147f24fB4DE",
        "topic": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
        "event": "Transfer",
        "args": {
            "0": "0x0000000000000000000000000000000000000000",
            "1": "0x038b5A07B1589B6a9fc7b0FF7CC64DdB922662B5",
            "2": "8881",
            "from": "0x0000000000000000000000000000000000000000",
            "to": "0x038b5A07B1589B6a9fc7b0FF7CC64DdB922662B5",
            "tokenId": "1"
        }
    }
]

通过交易哈希 getTransactionReceipt 获取后,返回以下内容。 怎么解码 decodeLog,获取到 tokenId 值,怎么用 php 实现,很多库好像不支持,也许是不会用。 试了个,web3p/web3.php 库, $web3->eth->abi->decodeLog() 一直提示 Call to a member function decodeLog() on bool,可能这个方法用不了。

然后又试了,也不行, $web3->eth->decodeLog() 提示 Unallowed rpc method: eth_decodeLog

{
    "transactionHash": "0xfbfc57d650998ff72d5c86c0ac8275b46ba75e4267d44b917e7ad5b80ede7898",
    "transactionIndex": "0x0",
    "blockNumber": "0x13d",
    "blockHash": "0x5bf3295f4ff7241b212cc980d5f85beff779842ec317ee7dd5cac64d2b8d09ca",
    "from": "0x038b5a07b1589b6a9fc7b0ff7cc64ddb922662b5",
    "to": "0x7bd38c5056234e91a2c9c11960007147f24fb4de",
    "cumulativeGasUsed": "0x2fcbb",
    "gasUsed": "0x2fcbb",
    "contractAddress": null,
    "logs": [
        {
            "address": "0x7bd38c5056234e91a2c9c11960007147f24fb4de",
            "blockHash": "0x5bf3295f4ff7241b212cc980d5f85beff779842ec317ee7dd5cac64d2b8d09ca",
            "blockNumber": "0x13d",
            "data": "0x",
            "logIndex": "0x0",
            "removed": false,
            "topics": [
                "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
                "0x0000000000000000000000000000000000000000000000000000000000000000",
                "0x000000000000000000000000038b5a07b1589b6a9fc7b0ff7cc64ddb922662b5",
                "0x00000000000000000000000000000000000000000000000000000000000022b1"
            ],
            "transactionHash": "0xfbfc57d650998ff72d5c86c0ac8275b46ba75e4267d44b917e7ad5b80ede7898",
            "transactionIndex": "0x0"
        }
    ],
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000200000020000000000000000000000010000080000000008000000000000000000000000000000000000000000000000020000000000000000000800000080000000000000080010000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000020000000000000000000000000000",
    "status": "0x1",
    "effectiveGasPrice": "0x9502f908",
    "type": "0x2"
}
请先 登录 后评论

最佳答案 2023-04-22 18:56

通过多方了解,php不适合弄web3,网上的库各种坑在里面。研究几天,决定放弃了。

请先 登录 后评论

其它 1 个回答

鬼才链(v+transbsc)
请先 登录 后评论