๐ Event Filtering: Topics & Indexed Parameters
Understand how to filter events by address, topics, and block range
Listen for smart contract events in real-time
Your Progress
0 / 5 completed๐ 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
๐ Generated Filter Code
{
"address": null,
"topics": [null],
"fromBlock": "latest"
}๐ฏ Filter Parameters Explained
null = all contracts (dangerous). "0x..." = specific contract. ["0x...", "0x..."] = multiple contracts. Use specific addresses when possible to reduce noise.
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.
"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: 0tries 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.