โ†
Previous Module
RPC Calls Visualizer

๐Ÿ” Event Filtering: Topics & Indexed Parameters

Understand how to filter events by address, topics, and block range

Listen for smart contract events in real-time

๐Ÿ” Filter What You Need

Without filters, you drown. Ethereum mainnet emits ~50,000 events per minute. If you subscribe to everything, your app crashes from data overload. Filters let you specify exactly what events you care about: specific contract addresses, specific event types, specific indexed parameters. You can filter by address (0x...), topics (event signature + indexed parameters), and block range. Smart filtering reduces noise by 99.9% and keeps your app performant.

๐ŸŽฎ Interactive: Filter Builder

Build a filtered subscription and see how it reduces event volume. Adjust address, event type, and block range to optimize your subscription.

๐Ÿ“Š Filter Impact

Estimated Event Rate
~50,000/min
โš ๏ธ Very noisy
Bandwidth Usage
Very High (500 MB/hour)
Recommended?
โœ— Too broad

๐Ÿ“ Generated Filter Code

{
  "address": null,
  "topics": [null],
  "fromBlock": "latest"
}

๐ŸŽฏ Filter Parameters Explained

address (Contract Address)

null = all contracts (dangerous). "0x..." = specific contract. ["0x...", "0x..."] = multiple contracts. Use specific addresses when possible to reduce noise.

topics (Event Signature + Indexed Params)

topics[0] = event signature hash (e.g., keccak256("Transfer(address,address,uint256)")). topics[1], topics[2], etc. = indexed parameters. Example: topics[1] = yourAddress filters Transfer events where you're the sender.

fromBlock / toBlock (Block Range)

"latest" = only new blocks (most common). "0x123abc" = specific block number. "pending" = mempool events (before mined). Historical range subscriptions are expensiveโ€”use getLogs for history, subscriptions for real-time.

โšก Performance Tips

  • โœ“Always filter by address when possible. Address filters are indexed and fast. Reduces events by 99%+.
  • โœ“Use indexed parameters in your smart contracts. Only indexed params can be filtered via topics. Max 3 indexed params per event.
  • โœ—Avoid null address + null topics. This subscribes to ALL events on the network. Your app will crash. Always filter something.
  • โš ๏ธDon't use large block ranges. fromBlock: 0 tries to send you every historical event. Use getLogs for history, not subscriptions.

๐Ÿ’ก Key Insight

Filtering isn't optionalโ€”it's essential for production apps. Unfiltered subscriptions are like drinking from a firehose: overwhelming and useless. The best practice is address + specific event signature. This combination reduces noise by 99.99% while giving you exactly what you need. For example, subscribing to Transfer events on USDC contract (address filter + topic[0] filter) gives you ~50 events/minute instead of 50,000. Your app stays responsive, your RPC provider stays happy, and your users get instant updates. Filter aggressively, always.

โ† Introduction