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
ObjectProperty | Type | Description |
---|---|---|
id | string | A unique identifier for the transaction. |
hash | string | The transaction's hash. |
index | number | The index of the transaction in the block. |
burnedBitcoin | BigNumberish | Amount of Bitcoin burned in the transaction. |
inputs | TransactionInput[] | List of transaction inputs. |
outputs | TransactionOutput[] | List of transaction outputs. |
OPNetType | OPNetTransactionTypes | The type of the OP_NET transaction (see below). |
gasUsed | bigint | The 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.