Post
Share your knowledge.
How can i get latest 10k logs from the blockchain using filter in ethersjs
i want to get logs for my contract address from the blockchain by .provider.getLogs() method . i am applying an filter to it with block range 0 to latest. it gives me error that it can only get logs up to 2k blocks or you can filter latest 10k logs . now I won't want to use the first case of 2k blocks . how can I configure my filter to get latest 10k logs . as there is no property in filter to cap logs amount.
const filter = {
address: ethers.utils.getAddress(address),
fromBlock: 0, // Start from the earliest block
toBlock: "latest", // Fetch logs until the latest block
};
- Smart Contract
- Solidity
- Optimizer
- Yul
- Solidity Compiler
Answers
1These limits are not one or another. Both limits are applied at the same time.
There is no filter configuration for that (client side). 2k blocks and 10k log limits are configured by the RPC provider (server side) that you are using. Other providers may have different limits.
10k logs limit means that if you are getting logs for a range of blocks (less than 2k blocks) and a number of events exceeds 10k then RPC will return to you only the first 10k events.
The general approach is to retrieve events with multiple calls.
- 1st call - fromBlock 0, toBlock 2000
- 2nd call - fromBlock 2001, toBlock 4000
and so on.
If you received exactly 10k logs for a call then it means the RPC provider excluded some of the events from the response and you need to re-run the call for a smaller range. However, that check is needed only if you expect such density of events for you filter.
Do you know the answer?
Please log in and share it.
Solidity is an object-oriented, high-level language for implementing smart contracts. It is a curly-bracket language designed to target the Ethereum Virtual Machine (EVM).
- My ERC721 contract successfully deploys, but I can't verify the contract's source code with hardhat21
- Solidity and ethers.js Compute Different Addresses from the Same Signature21
- can't understand what are the locations(uint256)22
- How to reverse keccak256 in solidity22
- Clarification on Gas Refunds and Comparison Between "require" and "revert" in Smart Contracts21