Kava
eth_uninstallFilter
The eth_uninstallFilter method removes a filter with the given ID. It should be used when a filter is no longer needed. While filters automatically timeout after a period of inactivity (typically 5 minutes), it's best practice to manually uninstall filters to properly manage resources.
Use Cases
- Properly terminating event listeners when monitoring is complete
- Cleaning up resources in dApps to prevent memory leaks
- Managing the complete filter lifecycle from creation to removal
- Optimizing node resources by removing unused filters
- Reducing API quota usage with service providers
- Preventing unexpected filter timeout errors
- Cleaning up after data collection tasks finish
- Implementing proper application shutdown procedures
Method Details
This method takes a filter ID and removes the corresponding filter.
Response Example
Return Values
- true: The filter was successfully uninstalled
- false: The filter could not be found or was already uninstalled
Why Uninstall Filters
While most Ethereum nodes automatically expire filters after a period of inactivity (typically 5 minutes), there are several reasons to explicitly uninstall filters:
- Resource Management: Active filters consume memory and processing resources on the node
- Filter Limits: Some nodes implement limits on the number of active filters per connection
- API Usage Optimization: Using fewer resources may reduce API costs with commercial providers
- Application Control: Explicit lifecycle management allows your application to know exactly when a filter is active
- Prevent Timeouts: Avoids unexpected "filter not found" errors when a filter times out automatically
- Clean Shutdown: Allows your application to properly clean up when terminating
Error Handling
When uninstalling filters, you might encounter the following scenarios:
-
Filter Already Removed:
- Attempting to uninstall a filter that was already uninstalled returns
false - No error is thrown
- Attempting to uninstall a filter that was already uninstalled returns
-
Invalid Filter ID:
- Attempting to uninstall a filter with an invalid ID format may result in an error
- Response will contain an error object instead of a result
-
Filter Expired:
- If a filter automatically expired due to inactivity, uninstalling it returns
false - No error is thrown
- If a filter automatically expired due to inactivity, uninstalling it returns
Best Practices
- Always clean up filters when they are no longer needed
- Handle connection interruptions by tracking active filters and reinstalling them
- Implement timeout handling for when filters expire automatically
- Add uninstall calls to application shutdown procedures
- Check the return value to verify successful uninstallation
- Keep track of active filters in your application state
- Don't assume uninstall will succeed - verify the result
- Implement retry logic for critical filter removal
Filter Types
This method works with all filter types created by:
eth_newFilter- Event log filterseth_newBlockFilter- New block notification filterseth_newPendingTransactionFilter- Pending transaction filters
See also
- eth_newFilter - Create a filter for event logs
- eth_getFilterChanges - Retrieve new logs since last poll
- eth_getFilterLogs - Get all logs matching filter criteria
- eth_newBlockFilter - Create filter for new blocks
- eth_newPendingTransactionFilter - Create filter for pending transactions
Parameters
Filter ID to uninstall