Overview
LogFilter specifies query parameters for filtering Ethereum event logs. Used with eth_getLogs (one-time query) and eth_newFilter (continuous polling). Supports filtering by block range, contract address, and event topics.
Type Definition (Zig)
Creating LogFilter
from
fromBlock: Starting block (bigint or tag)toBlock: Ending block (bigint or tag)address: Contract address(es) to filtertopics: Topic filter for indexed parametersblockhash: Specific block hash (alternative to range)
LogFilterType
Throws: InvalidLogFilterError if:
blockhashused withfromBlock/toBlock- Invalid block tags
- Invalid addresses or topics
Operations
matches
- Address (if specified)
- Block number range (if specified)
- Block hash (if specified)
- Topics (if specified)
isEmpty
true if filter has no criteria (would match all logs).
Block Range Queries
Block Tags
Block Numbers
Block Hash (Alternative)
Query logs from a specific block by hash (useful after reorgs):blockhash is mutually exclusive with fromBlock/toBlock.
Address Filtering
Single Address
Multiple Addresses (OR logic)
Topic Filtering
See TopicFilter for detailed topic matching rules.Usage with JSON-RPC
eth_getLogs (one-time query)
eth_newFilter (continuous polling)
Node Resource Limits
Ethereum nodes limit query scope to prevent resource exhaustion:Block Range Limits
- Infura: 10,000 blocks
- Alchemy: 2,000 blocks
- Local node: Configurable, often 5,000-10,000
Result Set Limits
Nodes may limit:- Number of logs returned (e.g., 10,000 max)
- Response size (e.g., 150MB max)
- Query complexity (multiple OR conditions)
- Query smallest block ranges possible
- Filter by contract address
- Add topic filters to narrow results
- Paginate by splitting block ranges
- Handle errors and retry with smaller ranges
Example: Paginated Query
Example: Token Transfer Monitor
Chain Reorganizations
When querying recent blocks, be aware of reorgs:Related Types
- TopicFilter - Event topic matching
- FilterId - Filter identifier for polling
- EventLog - Log entry structure
- BlockNumber - Block number type
- Address - Contract address type
JSON-RPC Methods
eth_getLogs- Query logs (one-time)eth_newFilter- Create filter for pollingeth_getFilterChanges- Poll for new logseth_getFilterLogs- Get all logs for filtereth_uninstallFilter- Remove filter

