eth_unsubscribe - Mantle

This method cancels an existing subscription. It requires a WebSocket connection.

Parameters

ParameterTypeDescription
subscriptionIdstringThe subscription ID returned by eth_subscribe

eth_unsubscribe requires a WebSocket connection.

Request (WebSocket)

ws-example.js

javascript// WebSocket connection required
const ws = new WebSocket('wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

ws.onopen = () => {
    ws.send(JSON.stringify({
        "jsonrpc": "2.0",
        "method": "eth_unsubscribe",
        "params": ["0x9ce59a13059e417087c02d3236a0b1cc"],
        "id": "getblock.io"
    }));
};

ws.onmessage = (event) => {
    console.log('Received:', JSON.parse(event.data));
};

axios-note.js

javascriptimport axios from 'axios';

// Note: eth_unsubscribe requires WebSocket
const data = JSON.stringify({
    "jsonrpc": "2.0",
    "method": "eth_unsubscribe",
    "params": ["0x9ce59a13059e417087c02d3236a0b1cc"],
    "id": "getblock.io"
});

console.log('WebSocket message:', data);

ws-example.py

pythonimport websocket
import json

def on_message(ws, message):
    print(f"Received: {message}")

def on_open(ws):
    ws.send(json.dumps({
        "jsonrpc": "2.0",
        "method": "eth_unsubscribe",
        "params": ["0x9ce59a13059e417087c02d3236a0b1cc"],
        "id": "getblock.io"
    }))

ws = websocket.WebSocketApp(
    "wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/",
    on_message=on_message,
    on_open=on_open
)
ws.run_forever()

rust-example.rs

rust// Note: eth_unsubscribe requires WebSocket connection
let message = r#"{
    "jsonrpc": "2.0",
    "method": "eth_unsubscribe",
    "params": ["0x9ce59a13059e417087c02d3236a0b1cc"],
    "id": "getblock.io"
}"#;

Response

response.json

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

Response Parameters

FieldTypeDescription
resultbooleanTrue if subscription was cancelled successfully

Use Case

The eth_unsubscribe method is essential for:

  • Cleaning up subscriptions
  • Resource management
  • Stopping event streams
  • Connection lifecycle management

Error Handling

Status CodeError MessageCause
403ForbiddenMissing or invalid ACCESS-TOKEN
-32000Subscription not foundInvalid subscription ID

Web3 Integration

ethers-unsubscribe.js

javascriptimport { ethers } from 'ethers';

const provider = new ethers.WebSocketProvider('wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

// Unsubscribe by removing listener
provider.off('block');
// Or close the connection
await provider.destroy();

viem-unsubscribe.js

javascriptimport { createPublicClient, webSocket } from 'viem';
import { mantle } from 'viem/chains';

const client = createPublicClient({
    chain: mantle,
    transport: webSocket('wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

const unwatch = client.watchBlocks({
    onBlock: (block) => console.log(block)
});

// Unsubscribe
unwatch();