Gets all transaction receipts for a given block by number or block hash.
Don’t have an API key?
Start using this method in your app today.
Description
Gets all transaction receipts for a given block by number or block hash.
Parameters
Name | Type | Description |
---|---|---|
params | object | The api only takes in one parameter - an object with at least a blockNumber or blockHash . If both are provided, blockHash is prioritized. |
params
Parameters
params
ParametersParameter | Type | Description |
---|---|---|
blockNumber | number | The block number you want to get transaction receipts for, in hex. |
blockHash | string | The block hash you want to get transaction receipts for. |
Response
Property | Type | Description |
---|---|---|
Promise<TransactionReceiptsResponse> | array of objects | A list of transaction receipts for each transaction in this block. |
TransactionReceiptsResponse
object parameters
TransactionReceiptsResponse
object parametersParameter | Type | Description |
---|---|---|
to | string | 20 Bytes - address of the receiver. null when its a contract creation transaction |
from | string | 20 Bytes - address of the sender |
contractAddress | string | 20 Bytes - The contract address created, if the transaction was a contract creation, otherwise null |
transactionIndex | number | Integer of the transactions index position log was created from. null when its pending log. |
root? | string | 32 bytes of post-transaction stateroot (pre Byzantium) |
gasUsed | number | The amount of gas used by this specific transaction alone |
logsBloom | string | 256 Bytes - Bloom filter for light clients to quickly retrieve related logs |
transactionHash | string | 32 Bytes - hash of the transaction |
logs | array | Array of log objects, which this transaction generated |
blockNumber | number | The block number where this log was in. null when its pending. null when its pending log. |
type | number | type |
status | integer | Either 1 (success) or 0 (failure) |
cummulativeGasUsed | number | A cummulative amount of gas used for the transaction. |
effectiveGasPrice | number | the 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 getTransactionReceipts
request using the Alchemy SDK:
// Imports the Alchemy SDK
const { Alchemy, Network, Utils } = 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 () => {
//Define the params object
const params = {
// blockNumber
blockNumber: "0x18760312114f3fdf11f9d5846245995835aa59994d5fc4203faee52d2f7eaabe"
};
//The response returns the transaction receipts of the `blockNumber`
let response = await alchemy.core.getTransactionReceipts(params)
//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
},
{
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 getTransactionReceipts
method using the code sandbox below:
Use Cases
Here are some possible use cases for the getTransactionReceipts
method:
-
Transaction Confirmation: You can use
getTransactionReceipts
to check if a transaction has been successfully confirmed by the EVM networks. A transaction receipt contains information such as the block number and transaction status, which can indicate if the transaction was successful or not. -
Contract Interaction: When you interact with a smart contract on the EVM networks, you typically receive a transaction hash. You can use
getTransactionReceipts
to retrieve the transaction receipt for that hash, which contains the contract address and any events emitted by the contract during the transaction. -
Transaction History: If you need to keep track of the transactions you have sent or received on the EVM networks, you can use
getTransactionReceipts
to retrieve the receipts for those transactions. You can then store this information in your application's database or use it to generate reports.
Related Methods
Here are the methods related to getTransactionReceipts
:
- getTransactionReceipt: Returns the transaction receipt for hash or null if the transaction has not been mined.