Fetching Transaction Receipt
This guide outlines the procedure for retrieving a transaction receipt via the getTransactionReceipt endpoint, utilizing the getTransactionReceipt
function in the Fireblocks SDK.
By employing the getTransactionReceipt
function of the Fireblocks SDK, you can obtain the receipt of any transaction that has been confirmed by the blockchain. This function takes in the baseAssetId
(indicating the blockchain) and the txHash
(indicating the transaction hash). It manages the process of querying the blockchain and returning the transaction receipt.
Note:
This functionality is exclusively available for EVM (Ethereum Virtual Machine) compatible chains.
Prerequisites
Before fetching a transaction receipt, ensure you have the following information:
- Base Asset ID: The
baseAssetId
of the blockchain where the transaction was executed (e.g., ETH for Ethereum). This is the Fireblocks ID of the blockchain's gas token. (To obtain the asset ID, refer to this assetId list). - Transaction Hash: The
txHash
of the transaction for which you wish to fetch the receipt. This is the unique identifier of the transaction on the blockchain and is a hex string (i.e. prefixed with 0x). You can obtain the transaction hash from the transaction details or the blockchain explorer.
Example: Fetching a Transaction Receipt
Below is an example of how to fetch a transaction receipt using the Fireblocks SDK:
1. Initialize the Fireblocks SDK
First, import the Fireblocks SDK and initialize it with your Fireblocks API key and private key:
import { Fireblocks, BasePath } from '@fireblocks/ts-sdk';
const privateKey = '...'; // Your Fireblocks API private key
const apiKey = '...'; // Your Fireblocks API key
const fireblocksSdk = new Fireblocks({
apiKey,
basePath: BasePath.US, // Use BasePath.EU for the EU region
secretKey: privateKey,
});
2. Fetch the Transaction Receipt
To fetch the transaction receipt, utilize the getTransactionReceipt
function of the Contract Interactions Controller:
const baseAssetId = 'ETH'; // The base asset ID for Ethereum
const txHash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'; // The transaction hash
const receipt = await fireblocks.getTransactionReceipt(baseAssetId, txHash);
console.log(receipt);
The response will be a transaction receipt object containing details about the transaction, such as the status, gas used, logs, and more.
Note:
For further information about the transaction receipt object, refer to the Endpoint Model section.
Endpoint Model
Transaction Receipt
The transaction receipt response object includes the following fields:
status
: The status of the transaction (e.g., success or failure).gasUsed
: The amount of gas consumed by the transaction.logs
: The logs generated by the transaction (if any).transactionHash
: The hash of the transaction.blockHash
: The hash of the block containing the transaction.blockNumber
: The number of the block containing the transaction.contractAddress
: The address of the contract created (if any).cumulativeGasUsed
: The cumulative gas used by the transaction.from
: The address of the sender.to
: The address of the receiver.effectiveGasPrice
: The actual price per unit of gas paid.type
: The type of the transaction.logs
: The logs generated by the transaction (if any).logsBloom
: The bloom filter for the logs of the transaction.transactionIndex
: The index of the transaction in the block.
Note:
The
logs
field contains an array of log objects, each representing a log generated by the transaction. Each
log object includes the following fields:
address
: The address of the contract that generated the log.topics
: An array of topics associated with the log.data
: The data contained in the log.blockNumber
: The number of the block containing the log.transactionHash
: The hash of the transaction that generated the log.transactionIndex
: The index of the transaction in the block.blockHash
: The hash of the block containing the log.logIndex
: The index of the log in the block.removed
: Indicates whether the log was removed.
Note:
Some fields may be empty in the response if the transaction has not been executed or if the blockchain does
not support them.
Updated 1 day ago