eth_unsubscribe - zkSync
Example code for the eth_unsubscribe JSON-RPC method. Сomplete guide on how to use eth_unsubscribe JSON-RPC in GetBlock.io Web3 documentation.
Cancels an existing subscription created with eth_subscribe. Like eth_subscribe, only available over WebSocket transport.
Parameters
subscriptionId
string
Yes
The subscription ID returned by eth_subscribe
Request Example
# This method requires WebSocket connection
wscat -c wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/
> {"jsonrpc":"2.0","method":"eth_unsubscribe","params":["0x1"],"id":"getblock.io"}const WebSocket = require('ws');
const ws = new WebSocket('wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'eth_unsubscribe',
params: ['0x1'],
id: 'getblock.io'
}));
});
ws.on('message', (data) => {
console.log(JSON.parse(data));
});import asyncio
import websockets
import json
async def unsubscribe():
uri = "wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
async with websockets.connect(uri) as ws:
payload = {
"jsonrpc": "2.0",
"method": "eth_unsubscribe",
"params": ["0x1"],
"id": "getblock.io"
}
await ws.send(json.dumps(payload))
response = await ws.recv()
print(json.loads(response))
asyncio.run(unsubscribe())Response Example
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": true
}Response Parameters
result
boolean
true if the subscription was cancelled, false if it did not exist
Use Cases
Stopping a live feed when the user navigates away
Reconnecting subscribers after a connection drop
Cleanup in WebSocket-based microservices
Error Handling
403
Forbidden
Missing or invalid <ACCESS-TOKEN>
-32602
Invalid params
Request parameters are missing or malformed
429
Too Many Requests
Rate limit exceeded for your plan
-32600
Invalid Request
eth_unsubscribe was called over HTTP; use a WebSocket connection instead
SDK Integration
Last updated
Was this helpful?