Skip to main content

Overview

BlockFilter represents a filter created by eth_newBlockFilter that notifies of new block hashes. Used for monitoring blockchain progress and detecting reorgs without polling full blocks.

Type Definition

Creating BlockFilter

from

Parameters:
  • filterId: FilterIdType - Filter identifier from eth_newBlockFilter
Returns: BlockFilterType

JSON-RPC Usage

Create Filter

Poll for Changes

Uninstall Filter

Example: Block Monitor

Example: Reorg Detector

Comparison with eth_subscribe

BlockFilter (eth_newBlockFilter)

Pros:
  • HTTP compatible (no WebSocket required)
  • Simple request-response pattern
  • Works with all RPC providers
Cons:
  • Polling-based (less efficient)
  • Delayed notifications (poll interval)
  • Filter expiration if not polled

eth_subscribe

Pros:
  • Real-time push notifications
  • More efficient (no polling)
  • No filter expiration
Cons:
  • Requires WebSocket connection
  • Not supported by all providers
  • More complex error handling

Filter Expiration

Block filters expire after inactivity (typically 5 minutes). Best practices:

Performance Considerations

Polling Frequency

Choose poll interval based on:
  • Block time (12s for Ethereum mainnet)
  • Filter expiration timeout
  • Application latency requirements

Batch Processing

Process multiple blocks efficiently:

Use Cases

Block Height Tracker

Transaction Confirmation Monitor

Network Activity Monitor

JSON-RPC Methods

  • eth_newBlockFilter - Create block hash filter
  • eth_getFilterChanges - Poll for new blocks
  • eth_uninstallFilter - Remove filter
  • eth_getBlockByHash - Fetch full block

See Also