githubEdit

eth_unsubscribe - Optimism

Example code for the eth_unsubscribe json-rpc method. Сomplete guide on how to use eth_unsubscribe json-rpc in GetBlock.io Web3 documentation.

This method cancels a subscription that was created with eth_subscribe. Once cancelled, no more notifications will be sent for that subscription. This should be called when real-time updates are no longer needed.

circle-exclamation

Parameters

Parameter
Type
Description
Required

subscriptionId

String

The subscription ID to cancel.

Yes

Request Sample

cURL (wscat)
# This method requires WebSocket connection
wscat -c wss://go.getblock.io/<ACCESS-TOKEN>/

> {"jsonrpc":"2.0","method":"eth_unsubscribe","params":["0x1"],"id":"getblock.io"}

Response

A successful response returns the following:

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": true
}

Response Parameters

  • id: A unique request identifier, matching the id sent in the request body.

  • jsonrpc: Specifies the use of JSON-RPC version 2.0.

  • result: Boolean indicating whether the subscription was successfully cancelled.

Use Case

The eth_unsubscribe method is commonly used for:

  • Subscription management

  • Resource cleanup

  • Connection lifecycle management

Error Handling

Error Code
Description

-32602

Invalid subscription ID

-32603

Internal error

SDK Integration

Last updated

Was this helpful?