eth_unsubscribe - Mantle
Example code for the eth_unsubscribe JSON-RPC method. Complete guide on how to use eth_unsubscribe JSON-RPC in GetBlock Web3 documentation.
This method cancels an existing subscription. It requires a WebSocket connection.
Parameters
Parameter
Type
Description
subscriptionId
string
The subscription ID returned by eth_subscribe
Request (WebSocket)
// WebSocket connection required
const ws = new WebSocket('wss://go.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));
};import 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);Response
Response Parameters
Field
Type
Description
result
boolean
True 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 Code
Error Message
Cause
403
Forbidden
Missing or invalid ACCESS-TOKEN
-32000
Subscription not found
Invalid subscription ID
Web3 Integration
Last updated
Was this helpful?