Skip to main content

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

Creating LogFilter

from

Parameters:
  • fromBlock: Starting block (bigint or tag)
  • toBlock: Ending block (bigint or tag)
  • address: Contract address(es) to filter
  • topics: Topic filter for indexed parameters
  • blockhash: Specific block hash (alternative to range)
Returns: LogFilterType Throws: InvalidLogFilterError if:
  • blockhash used with fromBlock/toBlock
  • Invalid block tags
  • Invalid addresses or topics

Operations

matches

Tests if a log entry matches the filter criteria. Checks:
  • Address (if specified)
  • Block number range (if specified)
  • Block hash (if specified)
  • Topics (if specified)

isEmpty

Returns 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):
Important: blockhash is mutually exclusive with fromBlock/toBlock.

Address Filtering

Single Address

Multiple Addresses (OR logic)

Matches logs from ANY of the specified addresses.

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

Common 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)
Best practices:
  • 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:

JSON-RPC Methods

  • eth_getLogs - Query logs (one-time)
  • eth_newFilter - Create filter for polling
  • eth_getFilterChanges - Poll for new logs
  • eth_getFilterLogs - Get all logs for filter
  • eth_uninstallFilter - Remove filter

See Also