Skip to main content

Fetching Transaction Receipt

The getTransactionReceipt method allows you to retrieve the receipt of a specific transaction on the OP_NET network. This receipt includes detailed information about the transaction's execution, such as logs, events, and proofs validating the receipt.


Method

getTransactionReceipt(txHash: string): Promise<TransactionReceipt>;
  • Parameters:

    • txHash: string: The hash of the transaction to fetch the receipt for.
  • Returns:

    • Promise<TransactionReceipt>: A transaction receipt object containing detailed information.

Object Definitions

TransactionReceipt Object
PropertyTypeDescription
receiptBufferThe raw receipt data (optional).
receiptProofsstring[]Proofs validating the transaction's receipt.
eventsContractEventsLogs emitted by the transaction, typically contract events.
revertBufferRevert reason for failed transactions (optional).

Example Usage

const txHash = "8bdb1b21a...";
const receipt = await provider.getTransactionReceipt(txHash);

console.log("Transaction Receipt:", receipt);
console.log("Receipt Proofs:", receipt.receiptProofs);
console.log("Events:", receipt.events);
if (receipt.revert) {
console.log("Revert Reason:", receipt.revert.toString("utf-8"));
}

Best Practices

  • Check the revert field to identify if the transaction failed.
  • Use the events property to analyze emitted logs, which are essential when interacting with smart contracts.
  • The receiptProofs provide cryptographic validation for the receipt, ensuring its integrity.

What’s Next?

After fetching the transaction receipt, you can: