getTransactionReceipt - SDK

Returns the transaction receipt for hash or null if the transaction has not been mined.

Don’t have an API key?

Start using this method in your app today.

Description

Returns the transaction receipt for hash or null if the transaction has not been mined.

Parameters

NameTypeDescription
transactionHashstring32 Bytes - Hash of a transaction.

Response

PropertyTypeDescription
Promise<TransactionReceipt / null>objectA transaction receipt object, or null when no receipt was found

TransactionReceipt response object parameters

ParameterTypeDescription
tostring20 Bytes - address of the receiver. null when its a contract creation transaction
fromstring20 Bytes - address of the sender
contractAddressstring20 Bytes - The contract address created, if the transaction was a contract creation, otherwise null
transactionIndexnumberInteger of the transactions index position log was created from. null when its pending log.
root?string32 bytes of post-transaction stateroot (pre Byzantium)
gasUsednumberThe amount of gas used by this specific transaction alone
logsBloomstring256 Bytes - Bloom filter for light clients to quickly retrieve related logs
transactionHashstring32 Bytes - hash of the transaction
logsarrayArray of log objects, which this transaction generated
blockNumbernumberThe block number where this log was in. null when its pending. null when its pending log.
typenumbertype
statusintegerEither 1 (success) or 0 (failure)
cummulativeGasUsednumberA cummulative amount of gas used for the transaction.
effectiveGasPricenumberthe gas price.

Example Request and Response

Prerequisite: You will need to install the Alchemy SDK before making requests with it.

The commands for installing it using npm or yarn are given below:

npm install alchemy-sdk
yarn add alchemy-sdk

Request

Here is an example of how to make a getTransactionReceipt request using the Alchemy SDK:

// Imports the Alchemy SDK
const { Alchemy, Network } = require("alchemy-sdk");

// Configures the Alchemy SDK
const config = {
    apiKey: "alchemy-replit", // Replace with your API key
    network: Network.ETH_MAINNET, // Replace with your network
};

// Creates an Alchemy object instance with the config to use for making requests
const alchemy = new Alchemy(config);

const main = async () => {
    //Initialize variables for the parameters
    const tx = "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"
    
    //Call the method to fetch the transaction receipt of the tx
    let response = await alchemy.core.getTransactionReceipt(tx)

    //Logging the response to the console
    console.log(response)
};

main();

Response

{
  to: '0xF02c1c8e6114b1Dbe8937a39260b5b0a374432bB',
  from: '0xa7d9ddBE1f17865597fBD27EC712455208B6B76d',
  contractAddress: null,
  transactionIndex: 65,
  gasUsed: BigNumber { _hex: '0x53a0', _isBigNumber: true },
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  blockHash: '0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2',
  transactionHash: '0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b',
  logs: [],
  blockNumber: 6139707,
  confirmations: 10565824,
  cumulativeGasUsed: BigNumber { _hex: '0x20ec2d', _isBigNumber: true },
  effectiveGasPrice: BigNumber { _hex: '0x04a817c800', _isBigNumber: true },
  status: 1,
  type: 0,
  byzantium: true
}

Code Sandbox

You can test out the getTransactionReceipt method using the code sandbox below:

Use Cases

Here are some potential use cases for the getTransactionReceipt method:

  • Confirming transaction execution: When a transaction is sent on the Ethereum blockchain, it may take some time for it to be processed and confirmed. The getTransactionReceipt method can be used to confirm that a particular transaction has been processed and its status (success or failure).

  • Verifying smart contract execution: Smart contracts are self-executing programs that run on the Ethereum blockchain. They can execute transactions and perform various operations on the blockchain. The getTransactionReceipt method can be used to verify that a smart contract has executed as intended and to check its output.

  • Tracking token transactions: Tokens are a type of digital asset that can be traded on the Ethereum blockchain. The getTransactionReceipt method can be used to track token transactions and to verify that they have been executed correctly.

  • Auditing blockchain transactions: The transparency and immutability of blockchain transactions make them an ideal platform for auditing purposes. The getTransactionReceipt method can be used to audit transactions and to ensure that they have been executed correctly and securely.

Related Methods

Here are the methods related to getTransactionReceipt:

ReadMe