Polygon
eth_getFilterLogs
The eth_getFilterLogs method returns an array of all logs matching the filter with the given ID. Unlike eth_getFilterChanges, which only returns new logs since the last poll, this method returns all logs that match the original filter criteria, regardless of whether they've been returned before, making it perfect for initializing application state or backfilling missed events.
Use Cases
- Initial data loading in dApps and wallet interfaces
- Historical event analysis and transaction history
- Smart contract state reconstruction from events
- Application state synchronization after downtime
- Complete event history retrieval and auditing
- Data analytics and comprehensive reporting
- Auditing contract interactions and governance
- Backfilling missed events after service disruption
- Token balance history reconstruction
- Market data analysis for trading applications
Method Details
This method takes a filter ID and returns all logs that match the filter criteria, providing a comprehensive view of historical events.
Response Example
Understanding Log Objects
Each log object contains the following comprehensive data:
- address: Contract address that generated the event
- topics: Array of 0-4 32-byte topics (indexed parameters)
- First topic is typically the event signature hash (keccak256 of event signature)
- Subsequent topics are indexed event parameters (each limited to 32 bytes)
- data: Contains the non-indexed event parameters (hex string)
- blockNumber: Block number where the log was created
- transactionHash: Transaction hash that generated the log
- transactionIndex: Transaction's index position in the block
- blockHash: Hash of the block where the log was created
- logIndex: Log index position in the block
- removed:
trueif the log was removed due to a chain reorganization
Decoding Log Data
To properly use event data, you need to decode it according to the event's ABI:
Difference from eth_getLogs
Both eth_getFilterLogs and eth_getLogs return logs matching criteria, but they have important differences:
-
Filter-based vs. Direct Query:
eth_getFilterLogsrequires creating a filter first witheth_newFiltereth_getLogstakes filter criteria directly in the request
-
Filter Reusability:
- With
eth_getFilterLogs, you can reuse the same filter ID for multiple calls - With
eth_getLogs, you must specify the criteria every time
- With
-
Resource Management:
eth_getFilterLogsrelies on server-side filter state, which may expireeth_getLogsis stateless and doesn't rely on server-side filter state
-
Typical Use Cases:
eth_getFilterLogsis useful in combination witheth_getFilterChangesfor ongoing monitoringeth_getLogsis often simpler for one-time historical queries
Common Filter Patterns
Here are some typical filter patterns used with this method:
Performance Considerations
- This method can be resource-intensive on the node provider
- For large date ranges, results can be very large
- May time out if too many logs match the criteria
- Consider using smaller block ranges for high-volume events
- Many providers limit the size of responses or the number of logs returned
- For very large datasets, batching by block ranges is recommended
- This call may be more expensive in terms of rate limiting than other methods
- Always check provider documentation for specific limitations
See also
- eth_newFilter - Create a filter for event logs
- eth_getFilterChanges - Retrieve new logs since last poll
- eth_uninstallFilter - Remove a filter when no longer needed
- eth_getLogs - Query logs without filter persistence
Parameters
The filter ID returned by eth_newFilter