Skip to main content

Overview

FilterId is a branded string type representing an opaque filter identifier returned by JSON-RPC filter creation methods (eth_newFilter, eth_newBlockFilter, eth_newPendingTransactionFilter). Filter IDs are used to poll for updates and uninstall filters.

Type Definition

Creating FilterId

from

Creates a FilterId from a string value. The string is typically a hex-encoded number returned by the node. Parameters:
  • value: string - Filter ID string
Returns: FilterIdType Throws: InvalidFilterIdError if value is not a string or is empty

Operations

toString

Converts a FilterId back to its string representation.

equals

Compares two FilterId instances for equality.

JSON-RPC Filter Lifecycle

Filters follow a request-response lifecycle on Ethereum nodes:

1. Create Filter

2. Poll for Changes

3. Get All Logs (log filters only)

4. Uninstall Filter

Filter Expiration

Filters automatically expire after a period of inactivity (typically 5 minutes). Nodes may:
  • Return empty arrays for expired filters
  • Return errors for invalid filter IDs
  • Silently drop old filters during node restarts
Best practices:
  • Poll filters regularly to prevent expiration
  • Handle filter not found errors gracefully
  • Recreate filters after node restarts

Example: Complete Filter Workflow

JSON-RPC Methods

  • eth_newFilter - Create log filter, returns FilterId
  • eth_newBlockFilter - Create block filter, returns FilterId
  • eth_newPendingTransactionFilter - Create pending tx filter, returns FilterId
  • eth_getFilterChanges - Poll for new results since last call
  • eth_getFilterLogs - Get all logs for log filter
  • eth_uninstallFilter - Remove filter from node

See Also