Getting started with TheRPC
Ethereum/Core API/eth_uninstallFilter

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.

Parameters:

The filter ID to uninstall

Returns:

true if the filter was successfully uninstalled, false otherwise

Response Example

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}

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:

  1. Resource Management: Active filters consume memory and processing resources on the node
  2. Filter Limits: Some nodes implement limits on the number of active filters per connection
  3. API Usage Optimization: Using fewer resources may reduce API costs with commercial providers
  4. Application Control: Explicit lifecycle management allows your application to know exactly when a filter is active
  5. Prevent Timeouts: Avoids unexpected "filter not found" errors when a filter times out automatically
  6. Clean Shutdown: Allows your application to properly clean up when terminating

Error Handling

When uninstalling filters, you might encounter the following scenarios:

  1. Filter Already Removed:

    • Attempting to uninstall a filter that was already uninstalled returns false
    • No error is thrown
  2. 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
  3. Filter Expired:

    • If a filter automatically expired due to inactivity, uninstalling it returns false
    • No error is thrown

Best Practices

  1. Always clean up filters when they are no longer needed
  2. Handle connection interruptions by tracking active filters and reinstalling them
  3. Implement timeout handling for when filters expire automatically
  4. Add uninstall calls to application shutdown procedures
  5. Check the return value to verify successful uninstallation
  6. Keep track of active filters in your application state
  7. Don't assume uninstall will succeed - verify the result
  8. Implement retry logic for critical filter removal

Filter Types

This method works with all filter types created by:

  1. eth_newFilter - Event log filters
  2. eth_newBlockFilter - New block notification filters
  3. eth_newPendingTransactionFilter - Pending transaction filters

See also

Help Us Get Better!
Share this page and help us create an even better product for you.