Fantom
Fantom
eth_unsubscribe
The eth_unsubscribe method cancels an existing WebSocket subscription to stop receiving event notifications. This method helps manage resources and network traffic by removing subscriptions that are no longer needed.
Use Cases
- Stopping event notifications when a user navigates away from a page
- Managing resources on both client and server to prevent memory leaks
- Cleaning up inactive subscriptions after data processing is complete
- Handling application state changes requiring different subscription parameters
- Keeping within provider limits on concurrent subscriptions
- Implementing subscription rotation for high-volume event monitoring
- Ensuring graceful shutdown of dApp event monitoring components
- Switching between different blockchain event types
- Freeing up server resources for other users in multi-tenant environments
- Managing sessions for user-specific event tracking
Method Details
This method cancels a subscription using its subscription ID.
Request Example
Response Example
Response Values
true: The subscription was successfully canceledfalse: No subscription existed with the given ID
Error Scenarios
| Error Code | Message | Description |
|---|---|---|
| -32602 | invalid subscription id | The provided subscription ID does not exist or is invalid |
| -32000 | subscription not found | The subscription was already canceled or never existed |
| -32603 | Internal error | Server encountered an unexpected condition |
Error Response Example
Important Notes
- This method must be called over the same WebSocket connection that created the subscription
- Closing the WebSocket connection automatically unsubscribes all associated subscriptions
- The subscription ID comes from the result of a previous eth_subscribe call
- You should unsubscribe from subscriptions that are no longer needed to free up server resources
- The same subscription ID cannot be reused after unsubscribing
- Some providers may limit the number of concurrent subscriptions per connection
- Subscription IDs are unique per connection and not globally unique
- If reconnecting to a different server in a load-balanced environment, old subscription IDs will not be valid
- Some RPC providers may automatically unsubscribe inactive subscriptions after a certain period
- Multiple unsubscribe attempts for the same ID are safe but will return false after the first successful attempt
See also
- eth_subscribe - Create WebSocket event subscriptions
- WebSocket Connection Guide - Working with persistent connections
- eth_getLogs - Alternative for historical event queries
- eth_newFilter - HTTP-based alternative for event filtering
- eth_getFilterChanges - Poll-based alternative to WebSockets
- eth_uninstallFilter - HTTP equivalent for cleaning up filters
Parameters
The subscription ID to cancel