BNB Smart Chain
BNB Smart Chain
eth_newBlockFilter
The eth_newBlockFilter method creates a filter in the node to notify when a new block arrives. This is a simpler and more efficient alternative to polling eth_blockNumber repeatedly, as it allows you to receive notifications only when new blocks are detected.
Use Cases
- Block synchronization for applications and explorers
- Triggering block-based actions in automated systems
- Confirmation tracking for transactions in wallets
- Chain reorganization detection for data integrity
- Real-time blockchain monitoring for analytics
- Gas price trend monitoring for fee optimization
- Mining/validation tracking in network analysis
- Detecting network stalls when blocks stop arriving
- Alerting systems for blockchain infrastructure
- Maintaining cache consistency with blockchain state
Method Details
This method takes no parameters and returns a filter ID that can be used with eth_getFilterChanges to poll for new blocks.
Response Example
How Block Filters Work
- When you create a block filter, the Ethereum node assigns it a unique ID
- The node keeps track of the latest block it has shown to your filter
- When you poll using
eth_getFilterChanges, it returns block hashes for any new blocks since your last poll - If no new blocks have been produced, it returns an empty array
Return Value Format
When polling with eth_getFilterChanges, this filter returns an array of block hashes:
Block Data Retrieval
The filter only returns block hashes. To get the full block data, you must make additional calls using:
eth_getBlockByHash- Get a block's details using its hash
Important Considerations
- Filter Expiration: Filters expire after a period of inactivity (typically around 5 minutes)
- Polling Frequency: Balance between timely updates and RPC call limits
- Block Reorganizations: Be aware that blocks can be reorganized, especially recent ones
- Chain Consistency: Block filters help maintain application state in sync with the blockchain
- Alternative Approaches:
- WebSocket
eth_subscribefor real-time push notifications - Polling
eth_blockNumberdirectly (less efficient)
- WebSocket
- Rate Limits: Excessive polling can lead to rate limiting from RPC providers
- Missing Blocks: If poll intervals are too large, you might need to handle multiple blocks at once
- Filter Management: Always uninstall filters when no longer needed
- Error Handling: Implement retry logic for temporary network issues
- Block Processing: Consider processing blocks sequentially to maintain data consistency
Comparison with Other Notification Methods
| Method | Purpose | Results | Best For |
|---|---|---|---|
eth_newBlockFilter | Notifies about new blocks | Array of block hashes | Block-level monitoring |
eth_newFilter | Notifies about specific log events | Array of log objects | Event-based applications |
eth_newPendingTransactionFilter | Notifies about pending transactions | Array of transaction hashes | Mempool monitoring |
WebSocket eth_subscribe | Push notifications (no polling) | Varies by subscription type | Real-time applications |
See also
- eth_getFilterChanges - Retrieve new block hashes since last poll
- eth_uninstallFilter - Remove a filter when no longer needed
- eth_getBlockByHash - Get block details by hash
- eth_newFilter - Create a filter for event logs
- eth_newPendingTransactionFilter - Create filter for pending transactions