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

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

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

通过交易哈希 getTransactionReceipt 获取后,返回以下内容。 我怎么获取到 event 名称 和 args 里面的数据如 tokenId,好像是要解码 topics 才能出来,不晓得怎么弄,web3.js 怎么实现,web3.php 怎么实现,其中一个举例子也行。

{
    "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:57

实现方法 encodeEventSignature,getTransactionReceipt,decodeLog

请先 登录 后评论

其它 3 个回答

zen
请先 登录 后评论
devChen
请先 登录 后评论
左敲右滑手艺人 - 币圈慈善家
请先 登录 后评论