How to use eth_getTransactionReceipt?

  • Tokenview
  • 更新于 2024-01-31 11:23
  • 阅读 1225

Getting Runlog of your transactions and Understanding the transaction proof on EVM

From the first day the EVM launched, there were logs saving the transaction detail information onto Ethereum blockchain. These logs indicate the counterparty of the transaction, the token the transaction triggered on, the events the transaction exposed out, the data the transaction attached onto the blockchain etc.

The logs, named receipts, are important as it is the transaction proof which could be verified and identified by any body using the pre-defined encoding-decoding spec of EVM. Usually there are 2 methods to get 2 different kinds of granularity log data. One is eth_getTransactionReceipt, the other is eth_getBlockReceiptseth_getTransactionReceipt is used to get one transaction’s receipt log, while eth_getBlockReceipts is used to get all transactions’ receipt logs in a block. We will introduce eth_getTransactionReceipt in this artical, eth_getBlockReceipts is same, but a list.

How to use eth_getTransactionReceipt?

RPC eth_getTransactionReceipt is an interface to interact with EVM node to retrieve information of one transaction, so you have to call it from a local node or node service provider. Here is the curl syntax using Tokenview node service.

curl -H "Content-Type:application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0x855aff97389df84541994e8133b15c01570d844a005035bc8bcc68ecd186f388"],"id":1}' https://services.tokenview.io/vipapi/nodeservice/eth?apikey={apikey}

The input parameter is the transaction hash, an archive node can return all the receipts of all transactions happened on blockchain, and a full node can only return the latest transactions in latest x blocks, in it x depends on the configration of the full node.

Below is the normal response of this RPC. The result[‘log’][{array_index}][‘topics’] tells what function is called, what parameters are input into the function, result[‘log’][{array_index}][‘data’] tells the undefined parameter part.

{
    "jsonrpc":"2.0",
    "id":1,
    "result":{
        "blockHash":"0x330c5980143835f1b4683d2546556157cf20874d7ad1e4490c6d43ac07d1a2ac",
        "blockNumber":"0x101b6fe",
        "contractAddress":null,
        "cumulativeGasUsed":"0x1da47",
        "effectiveGasPrice":"0x9228e3f44",
        "from":"0x1cad683486c7c6f3a21d9a522e5d5cbb02d9c35e",
        "gasUsed":"0x1da47",
        "logs":[
            {
                "address":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
                "topics":[
                    "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
                    "0x00000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
                    "0x000000000000000000000000280027dd00ee0050d3f9d168efd6b40090009246"
                ],
                "data":"0x0000000000000000000000000000000000000000000000000000000ea945ebaa",
                "blockNumber":"0x101b6fe",
                "transactionHash":"0x855aff97389df84541994e8133b15c01570d844a005035bc8bcc68ecd186f388",
                "transactionIndex":"0x0",
                "blockHash":"0x330c5980143835f1b4683d2546556157cf20874d7ad1e4490c6d43ac07d1a2ac",
                "logIndex":"0x0",
                "removed":false
            },
            {
                "address":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
                "topics":[
                    "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
                    "0x000000000000000000000000280027dd00ee0050d3f9d168efd6b40090009246",
                    "0x00000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f5640"
                ],
                "data":"0x000000000000000000000000000000000000000000000001f0a591a58d8d6000",
                "blockNumber":"0x101b6fe",
                "transactionHash":"0x855aff97389df84541994e8133b15c01570d844a005035bc8bcc68ecd186f388",
                "transactionIndex":"0x0",
                "blockHash":"0x330c5980143835f1b4683d2546556157cf20874d7ad1e4490c6d43ac07d1a2ac",
                "logIndex":"0x1",
                "removed":false
            },
            {
                "address":"0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
                "topics":[
                    "0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67",
                    "0x000000000000000000000000280027dd00ee0050d3f9d168efd6b40090009246",
                    "0x000000000000000000000000280027dd00ee0050d3f9d168efd6b40090009246"
                ],
                "data":"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff156ba1456000000000000000000000000000000000000000000000001f0a591a58d8d60000000000000000000000000000000000000005d1a8c54a104574892942ca7de000000000000000000000000000000000000000000000000010bf798ba50c260d50000000000000000000000000000000000000000000000000000000000031373",
                "blockNumber":"0x101b6fe",
                "transactionHash":"0x855aff97389df84541994e8133b15c01570d844a005035bc8bcc68ecd186f388",
                "transactionIndex":"0x0",
                "blockHash":"0x330c5980143835f1b4683d2546556157cf20874d7ad1e4490c6d43ac07d1a2ac",
                "logIndex":"0x2",
                "removed":false
            }
        ],
        "logsBloom":"0x00000000010000000000000000000000000000020000000000000000040000000000000000000000000008000000000002000000080020000000000000000000000000000000000808000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000800000000000000000000000000000000000000000000010100000000000000000000000000000000200000000000000000000000000000000000002000000008000000000002000000000000000000002000000000000000000000000000000000000000200000000000000010000000000000000000000000000000000000000000",
        "status":"0x1",
        "to":"0x280027dd00ee0050d3f9d168efd6b40090009246",
        "transactionHash":"0x855aff97389df84541994e8133b15c01570d844a005035bc8bcc68ecd186f388",
        "transactionIndex":"0x0",
        "type":"0x2"
    }
}

Tokenview already showed these logs on their transaction page, check the first part of the result[‘log’][0], address is 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48, topics[0] is the function, topics[1] and topics[2] are the parameters of the function, data is the undefined parameter.

Switch back to the Transaction Info on that page, 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 is USDC, the function is Transfer, and the token transfer happened from 0x88e6 to 0x2800, the data is the value transferred, 62969473962 is the raw data of USDC, divided by USDC’s decimal 6, equals to 62969.473962.

Well done, you’ve got the core of eth_getTransactionReceipt, a must-have skill for indexing services.

Tokenview is a general multi-crypto blockchain explorer, and it is also a Developer Platform. You would be able to query your wallet balance, the transaction list on your wallet with end-user, and you also get the detail data from Blockchain APIs provided by Tokenview Developer Platform.

点赞 0
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
Tokenview
Tokenview
Tokenview支撑120+条公链,包含自建公链节点,公链浏览器tokenview.io,公链数据API,公链富豪榜数据,公链智能合约,公链上所有交易数据,集丰富的区块链数据种类,数量于一体,其数据可被区块链各领域的开发者所使用,其API接口结构化易于使用,其准确度经多层校验精准完备。