Ethereum
eth_getLogs
eth_getLogs returns all event logs that match a filter object. It's the foundational call for indexers, analytics pipelines, and any one-shot backfill that doesn't need a live subscription. Pair it with batching and you have a complete pull-based indexing strategy.
Filter shape
The filter is a single JSON object:
| Field | Type | Description |
|---|---|---|
fromBlock | string | Lower bound — hex block number or tag (earliest, latest, pending, safe, finalized). |
toBlock | string | Upper bound — same shape as fromBlock. |
address | string | string[] | One contract address or an array of addresses to filter on. |
topics | (string | string[] | null)[] | Position-indexed topic filters. null matches anything in that slot. |
blockHash | string | Restrict to a single block by hash. Cannot be combined with fromBlock/toBlock. |
The topics array is positional. Each slot holds either a single 32-byte topic hash, an array of alternatives (OR), or null (any). Topic 0 is conventionally the event signature hash.
Response shape
An array of log objects:
Sizing the request
eth_getLogs is one of the most expensive RPC methods in terms of upstream load. Keep these limits in mind:
- Block range: TheRPC caps a single call at ~10,000 blocks. Larger windows return
query exceeds max block range. Paginate. - Result size: Responses over 1 MB are truncated. If a single block returns many matches, narrow
addressortopics. - Indexing: Filter by
addressandtopics[0]when you can. Filtering bytopicsalone scans every contract.
Anti-patterns
- Don't poll
eth_getLogswithfromBlock: "latest"in a tight loop. Use eth_newFilter + eth_getFilterChanges, or subscribe via eth_subscribe over a WebSocket endpoint. - Don't pass huge address arrays. A long
address: [...]array isn't a free win — providers serialize it linearly. Bucket and parallelise instead. - Don't forget about reorgs. Logs from non-finalized blocks can disappear. For systems of record, re-query after a few blocks of confirmation or query against the
finalizedtag.
See also
- eth_newFilter — server-side filter for incremental polling.
- eth_getFilterLogs — replay all logs that a filter would have caught.
- eth_subscribe — push-based logs over WebSocket.
Parameters
JSON filter object: { fromBlock?, toBlock?, address?, topics? }