eth_getTransactionReceipt - TRON

Retrieve transaction details using 'eth_getTransactionReceipt' via Tron’s JSON-RPC API Interface.

Description

The 'eth_getTransactionReceipt' Web3 method in the Tron protocol is a crucial tool for developers needing detailed information about a specific transaction. By utilizing the 'eth_getTransactionReceipt' RPC protocol, users can obtain comprehensive data such as block number, transaction status, gas used, and logs generated by the transaction. This method is part of Tron’s JSON-RPC API Interface, designed to facilitate seamless integration and interaction with the Tron blockchain. It is particularly useful for verifying transaction success and analyzing event logs. Whether you're building dApps or conducting audits, this method provides the necessary insights to enhance your blockchain solutions.

Supported Networks

The eth_getTransactionReceipt RPC method supports the following network types

  • Mainnet

  • Testnets

Parameters

Here is the list of parameters eth_getTransactionReceipt method needs to be executed.

  • Transaction Hash

    • Type: String

    • Description: The hash of the transaction for which the receipt is requested.

    • Required: Yes

    • Default/Supported Values: A 32-byte hash value, typically represented as a hexadecimal string prefixed with "0x".

URL

https://go.getblock.io/<ACCESS-TOKEN>/

Here’s a sample cURL request using eth_getTransactionReceipt

Request

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/jsonrpc' 
--header 'Content-Type: application/json' 
{"jsonrpc": "2.0", "method": "eth_getTransactionReceipt", "params": ["c9af231ad59bcd7e8dcf827afd45020a02112704dce74ec5f72cb090aa07eef0"], "id": "getblock.io"}

Response


{
  "jsonrpc": "2.0",
  "id": "getblock.io",
  "result": null
}

Body Parameters

Here is the list of body parameters for the eth_getTransactionReceipt method response:

  1. transactionHash: The hash of the transaction. This is a unique identifier for the transaction.

  2. transactionIndex: The transaction index position in the block.

  3. blockHash: The hash of the block where this transaction was included.

  4. blockNumber: The block number where this transaction was included.

  5. from: The address of the sender.

  6. to: The address of the receiver. If it is a contract creation transaction, the to field is null.

  7. cumulativeGasUsed: The total amount of gas used when this transaction was executed in the block.

  8. gasUsed: The amount of gas used by this specific transaction.

  9. contractAddress: The contract address created, if the transaction was a contract creation, otherwise null.

  10. logs: An array of log objects, which this transaction generated.

  11. logsBloom: A 256-byte Bloom filter for light clients to quickly retrieve related logs.

  12. status: The status of the transaction execution. It is either 1 (success) or 0 (failure).

  13. effectiveGasPrice: The actual gas price paid for the transaction, which can vary due to the dynamic fee structure in EIP-1559.

Use Case

Here are some use-cases for the eth_getTransactionReceipt method:

  1. Transaction Confirmation: One of the primary use-cases for the eth_getTransactionReceipt method is to confirm the successful inclusion of a transaction in the blockchain. Developers often use this method to check whether a transaction has been mined and included in a block. By retrieving the transaction receipt, they can verify important details such as the block number, gas used, and status, which indicates whether the transaction was successful or failed.

  2. Smart Contract Event Monitoring: This method is essential for applications that need to monitor events emitted by smart contracts. When a transaction interacts with a smart contract, it may trigger specific events. By using eth_getTransactionReceipt, developers can access the logs section of the receipt, which contains these events. This is particularly useful for decentralized applications (dApps) that rely on event-driven architectures to update user interfaces or trigger further actions based on smart contract activity.

  3. Gas Usage Analysis: Developers can use the transaction receipt to analyze the gas usage of a transaction. The receipt provides information on the total gas used as well as the gas price, allowing developers to calculate the cost of executing a transaction. This is valuable for optimizing smart contract functions and managing transaction fees, especially in environments where gas prices fluctuate significantly.

Code for eth_getTransactionReceipt

import requests
import json

url = "https://go.getblock.io/<ACCESS-TOKEN>/"
headers = {
    "Content-Type": "application/json"
}
payload = {"jsonrpc": "2.0", "method": "eth_getTransactionReceipt", "params": ["c9af231ad59bcd7e8dcf827afd45020a02112704dce74ec5f72cb090aa07eef0"], "id": "getblock.io"}

response = requests.post(url, headers=headers, data=json.dumps(payload))

# Check the response and print the result
if response.status_code == 200:
    print("Result:", response.json().get("result"))
else:
    print("Error:", response.status_code, response.text)

Common Errors

Common Errors When using the eth_getTransactionReceipt RPC Tron method, the following issues may occur:

  • Transaction Not Found: If the transaction hash is incorrect or the transaction has not yet been mined, the receipt will not be available. Ensure the transaction hash is accurate and check the transaction status before retrying.

  • Node Synchronization Lag: If the node is not fully synchronized with the network, it may not have the latest transaction data. Use a fully synchronized node or a reliable node provider to avoid this issue.

  • Network Congestion: High network traffic can delay the availability of transaction receipts. Consider increasing the gas price to expedite transaction processing during peak times.

  • Invalid Parameters: Incorrectly formatted parameters can lead to errors. Verify that the transaction hash is a valid hexadecimal string and matches the expected format.

Using the eth_getTransactionReceipt method in Web3 applications is crucial for confirming the status and details of blockchain transactions. It provides developers with essential information such as gas usage and event logs, enabling robust transaction tracking and error handling within decentralized applications.

conclusion

The eth_getTransactionReceipt RPC method is a crucial tool for retrieving transaction details on the Ethereum blockchain, providing insights into transaction status and logs. While primarily associated with Ethereum, understanding its functionality is beneficial for developers working across different blockchain platforms, including Tron, as it aids in efficient transaction tracking and debugging.

Last updated