Skip to main content

Fetching Transaction Data

The getTransaction method allows you to retrieve detailed information about a specific transaction on the OP_NET network. You can fetch transactions by their hash and analyze their details, including gas usage, inputs, outputs, and transaction type.


Method

getTransaction(txHash: string): Promise<TransactionBase<OPNetTransactionTypes>>;
  • Parameters:

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

    • Promise<TransactionBase<OPNetTransactionTypes>>: A transaction object containing its details.

Object Definitions

TransactionBase Object
PropertyTypeDescription
idstringA unique identifier for the transaction.
hashstringThe transaction's hash.
indexnumberThe index of the transaction in the block.
burnedBitcoinBigNumberishAmount of Bitcoin burned in the transaction.
inputsTransactionInput[]List of transaction inputs.
outputsTransactionOutput[]List of transaction outputs.
OPNetTypeOPNetTransactionTypesThe type of the OP_NET transaction (see below).
gasUsedbigintThe amount of gas used by the transaction.

Example Usage

const txHash = "8bdb1b21a...";
const transaction = await provider.getTransaction(txHash);

console.log("Transaction ID:", transaction.id);
console.log("Transaction Hash:", transaction.hash);
console.log("Gas Used:", transaction.gasUsed);
console.log("Transaction Type:", transaction.OPNetType);

Best Practices

  • Ensure the txHash provided is valid and exists on the network you are connected to.
  • The transaction type (OPNetType) helps you identify if the transaction is a deployment, interaction, or generic.
  • Use this method to retrieve metadata such as sender, receiver, value, and gas usage.

What’s Next?