web3.js
web3.js copied to clipboard
RPC Method `eth_getBlockReceipts` not supported
Hi team
This eth_getBlockReceipts
method retrieves all transaction receipts for a given block. Transaction receipts contain information about the execution status of a transaction and can be useful for monitoring the status of transfers or contract execution on the blockchain.
Use case
The eth_getBlockReceipts allows you to retrieve the receipts for all transactions in a specific block. A practical use case can be to retrieve all of the logs emitted from the transactions in a block. The method returns an array of transaction receipts, where each contains information about the transaction and any logs generated as a result of the transaction execution, so the logs can be isolated.
You can test it here: eth_getBlockReceipts | Ethereum
Supported by:
Not supported/Not listed:
Ethers doesn't have a method getBlockReceipts()
but it allows developers to use await provider.send('eth_getBlockReceipts', [blockNumber]);
which is useful.
Junaid shared with me the web3.extend test and I was able to do this as a temporary solution (i didn't know about this web3.extend
so it might be useful to write a simple guide about it in the docs, I will do it)
const { Web3 } = require("web3");
const web3 = new Web3(
"https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"
);
async function main() {
web3.extend({
property: "L2Module",
methods: [
{
name: "getBlockReceipts",
call: "eth_getBlockReceipts",
},
],
});
const receipts = await web3.L2Module.getBlockReceipts("latest"); //return all the receipts
let logs = receipts.flatMap((receipt) => receipt.logs); //array of logs
console.log(logs); //print logs
}
main();
Will use #6768 instead of this one and use web3 extend.