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> | object | A list of transaction receipts for each transaction in this block. |
TransactionReceiptsResponse
object parameters
TransactionReceiptsResponse
object parametersProperty | Type | Description |
---|---|---|
receipts | array of objects | A list of transaction receipts for the queried block. |
receipts
object parameters
receipts
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 | null | 20 Bytes - The contract address created, if the transaction was a contract creation, otherwise null |
transactionIndex | number | The integer of the transactions index position log was created from. null when it's pending log. |
root? | string | 32 bytes of post-transaction stateroot (pre Byzantium) |
gasUsed | object | The amount of gas used by this specific transaction alone. It returns the type: BigNumber , and the hexadecimal representation of the gas used in the hex property. |
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. |
confirmations | number | The number of confirmations for the transaction. |
type | number | type. |
status | integer | Either 1 (success) or 0 (failure) |
cummulativeGasUsed | object | A cumulative amount of gas used for the transaction. It returns the type: BigNumber , and the hexadecimal representation of the cumulative gas used in the hex property. |
effectiveGasPrice | number | The gas price. It returns the type: BigNumber , and the hexadecimal representation of the effective gas in the hex property. |
byzantium | boolean | Returns true/false. |
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@latest
yarn add alchemy-sdk@latest
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
{
"receipts": [
{
"transactionHash": "0xcbe7ce4c134f142265f66002865b9c70c653f331db166bd04145d017099d32a5",
"blockHash": "0x18760312114f3fdf11f9d5846245995835aa59994d5fc4203faee52d2f7eaabe",
"blockNumber": "0xedd023",
"logs": [
{
"transactionHash": "0xcbe7ce4c134f142265f66002865b9c70c653f331db166bd04145d017099d32a5",
"address": "0xb4b9dc1c77bdbb135ea907fd5a08094d98883a35",
"blockHash": "0x18760312114f3fdf11f9d5846245995835aa59994d5fc4203faee52d2f7eaabe",
"blockNumber": "0xedd023",
"data": "0x000000000000000000000000000000000000000000001e52bf853982a7320000",
"logIndex": "0x0",
"removed": false,
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000e93381fb4c4f14bda253907b18fad305d799241a",
"0x000000000000000000000000b93e6551a61305b7a5c9621599f0d054aab6f17d"
],
"transactionIndex": "0x0"
}
],
"contractAddress": null,
"effectiveGasPrice": "0x6fc23ac00",
"cumulativeGasUsed": "0x10569",
"from": "0xe93381fb4c4f14bda253907b18fad305d799241a",
"gasUsed": "0x10569",
"logsBloom": "0x00020000000000000000000000000000000000000000000000000000000000000000040000000000000000010000000000000000010000000000000000000000000000000000000000000008000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000010000000000000000000800000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000100000000000002000000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"to": "0xb4b9dc1c77bdbb135ea907fd5a08094d98883a35",
"transactionIndex": "0x0",
"type": "0x0"
},
{
"transactionHash": "0xf0605f4c7e07737142a6dfccf44dd77faab6574404bf99faab9e347addeef728",
"blockHash": "0x18760312114f3fdf11f9d5846245995835aa59994d5fc4203faee52d2f7eaabe",
"blockNumber": "0xedd023",
"logs": [
{
"transactionHash": "0xf0605f4c7e07737142a6dfccf44dd77faab6574404bf99faab9e347addeef728",
"address": "0xb4b9dc1c77bdbb135ea907fd5a08094d98883a35",
"blockHash": "0x18760312114f3fdf11f9d5846245995835aa59994d5fc4203faee52d2f7eaabe",
"blockNumber": "0xedd023",
"data": "0x000000000000000000000000000000000000000000005ec4c3f70f248b8a0000",
"logIndex": "0x1",
"removed": false,
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000e93381fb4c4f14bda253907b18fad305d799241a",
"0x0000000000000000000000005e8304b5600cccba6d6292c6687ac9ead0ec6288"
],
"transactionIndex": "0x1"
}
],
"contractAddress": null,
"effectiveGasPrice": "0x6fc23ac00",
"cumulativeGasUsed": "0x20ad2",
"from": "0xe93381fb4c4f14bda253907b18fad305d799241a",
"gasUsed": "0x10569",
"logsBloom": "0x00000000000000000000000000000000000002000000000000000000000000000000000000000000000000010000000000000000010000000000000000000000000000000000000000000008040000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000010000000000000000000800000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"to": "0xb4b9dc1c77bdbb135ea907fd5a08094d98883a35",
"transactionIndex": "0x1",
"type": "0x0"
},
{
"transactionHash": "0xf54f3420c1f7504d3260d3e9cd48521dc42785317df2f280d63fc614f731008c",
"blockHash": "0x18760312114f3fdf11f9d5846245995835aa59994d5fc4203faee52d2f7eaabe",
"blockNumber": "0xedd023",
"logs": [
{
"transactionHash": "0xf54f3420c1f7504d3260d3e9cd48521dc42785317df2f280d63fc614f731008c",
"address": "0x0820aeb0add3ffa988d00aea416e98e7099d0aa8",
"blockHash": "0x18760312114f3fdf11f9d5846245995835aa59994d5fc4203faee52d2f7eaabe",
"blockNumber": "0xedd023",
"data": "0x",
"logIndex": "0x1f",
"removed": false,
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x000000000000000000000000252f6c8b09de8d7690c605dde04930a39bfcc2b5",
"0x00000000000000000000000000000000000000000000000000000000000000d4"
],
"transactionIndex": "0x1d"
}
],
"contractAddress": null,
"effectiveGasPrice": "0x1f2198025",
"cumulativeGasUsed": "0x1d41ca",
"from": "0x252f6c8b09de8d7690c605dde04930a39bfcc2b5",
"gasUsed": "0x1a522",
"logsBloom": "0x00000000000000000000000000000001000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000008000000000000004000000000000000000000000000000000020000000000000000000800000000000000020000000110000000000000000000000000000000000000000000000100000040000000000000000000000000000000000000000000000000000000200000000000000000000000000000000002000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"to": "0x0820aeb0add3ffa988d00aea416e98e7099d0aa8",
"transactionIndex": "0x1d",
"type": "0x2"
}
]
}
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 the EVM networks have successfully confirmed a transaction. 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.