eth_getTransactionReceipt - BNB Smart Chain
Retrieve transaction receipt details on the BSC protocol using the eth_getTransactionReceipt method via the JSON-RPC API Interface.
The RPC method retrieves transaction receipt details on BSC, including status, block number, gas used, and logs, confirming transaction execution.
The eth_getTransactionReceipt
method in the BSC protocol is a crucial part of both the eth_getTransactionReceipt
Web3 and eth_getTransactionReceipt
RPC protocol. It retrieves the receipt of a transaction by its hash, providing details such as status, gas used, and logs generated during execution.
Accessible via JSON-RPC, eth_getTransactionReceipt
is indispensable for verifying transaction outcomes and debugging smart contracts. It returns null
for pending transactions, ensuring users can efficiently track transaction finality and network interactions with precision and ease.
Supported Networks
The eth_getTransactionReceipt
JSON-RPC API method supports the following network types:
Mainnet
Testnet
Parameters
Here is the list of parameters eth_getTransactionReceipt
method needs to be executed. Always format the method name as inline code (wrapped in backticks).
Transaction Hash
Type: String
Description: The hash of the transaction for which the receipt is being requested.
Required: Yes
Default/Supported Values: A 32-byte hash represented as a hexadecimal string, prefixed with "0x".
Request Example
API Endpoint
Request
Here’s a sample cURL request using eth_getTransactionReceipt
:
Response
Below is a sample JSON response returned by eth_getTransactionReceipt
upon a successful call:
Body Parameters
Here is the list of body parameters for the eth_getTransactionReceipt
method:
blockHash: The hash of the block where this transaction was included.
blockNumber: The block number where this transaction was included.
contractAddress: The contract address created, if the transaction was a contract creation, otherwise
null
.cumulativeGasUsed: The total amount of gas used when this transaction was executed in the block.
effectiveGasPrice: The effective gas price paid for this transaction.
from: The address of the sender.
gasUsed: The amount of gas used by this specific transaction alone.
logs: An array of log objects, which this transaction generated.
logsBloom: A bloom filter of logs generated by this transaction.
status: The status of the transaction, either
0x1
(success) or0x0
(failure).to: The address of the receiver.
null
when it's a contract creation transaction.transactionHash: The hash of the transaction.
transactionIndex: The index position of the transaction in the block.
type: The type of transaction (e.g.,
0x0
for legacy transactions).
Use Cases
Here are some use-cases for eth_getTransactionReceipt
method:
Transaction Confirmation: One of the primary uses of the
eth_getTransactionReceipt
method is to confirm whether a transaction has been successfully mined and included in a block. By retrieving the transaction receipt, developers can check thestatus
field to determine if the transaction succeeded or failed. This is crucial for applications that need to ensure that a transaction, such as a token transfer or a smart contract interaction, has been completed successfully before proceeding with further operations.Gas Usage Analysis: The
eth_getTransactionReceipt
method provides detailed information about the gas used by a transaction. Developers can use this data to analyze the efficiency of their smart contracts and optimize gas usage. The receipt includes thegasUsed
field, which indicates the amount of gas consumed by the transaction, allowing developers to identify potentially expensive operations and make necessary adjustments.Event Logs Retrieval: Another important use case for
eth_getTransactionReceipt
is to access the logs generated by a transaction. When a smart contract emits events, these are recorded in the transaction receipt'slogs
field. Developers can use this information to trigger off-chain actions, update application states, or monitor specific events within the blockchain. This capability is essential for building interactive and responsive decentralized applications (dApps).
Code for eth_getTransactionReceipt
Common Errors
When using the eth_getTransactionReceipt
JSON-RPC API BSC method, the following issues may occur:
The transaction hash may be incorrect or malformed, resulting in a null response. Ensure the transaction hash is a valid 32-byte hexadecimal string prefixed with "0x".
If the transaction is pending, the receipt will not be available. Wait for the transaction to be mined and then re-query for the receipt.
Network congestion or node issues can lead to timeouts or delays in receiving a response. Consider retrying the request or using a different node provider to mitigate this issue.
Using the eth_getTransactionReceipt
method in Web3 applications provides critical information about transaction outcomes, including status, gas used, and logs generated. This method is essential for verifying transaction success and debugging smart contract interactions, enhancing the reliability and transparency of decentralized applications.
Conclusion
The eth_getTransactionReceipt
method is a crucial JSON-RPC call used to retrieve the status and details of a specific transaction on blockchain networks like Ethereum and BNB Smart Chain (BSC). By providing the transaction hash, users can obtain information such as block number, gas used, and logs, which are essential for verifying transaction success and debugging smart contracts. This makes eth_getTransactionReceipt
an indispensable tool for developers and users interacting with decentralized applications on BSC and other Ethereum-compatible networks.
Last updated