slotsUpdatesUnsubscribe
The Solana slotsUpdatesUnsubscribe method cancels a slot updates subscription created by slotsUpdatesSubscribe so that slot update notifications are no longer received.
Usage Notes
- Must be called via a WebSocket endpoint; HTTP is not supported.
- After unsubscribing, the subscription cannot be re-established using the same subscription ID. If a new subscription is needed, call slotsUpdatesSubscribe again.
- If the WebSocket connection is closed, subscriptions are automatically cancelled, so subscriptions must be re-established upon reconnection.
- ⚠️ This subscription is unstable. The subscription format may change in the future and may not always be supported.
1. Request
Parameters
The slot updates unsubscribe request has the following parameters.
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | integer or string | required | Unique identifier for the request. Used by the client to match requests with responses. |
| jsonrpc | string | required | JSON-RPC protocol version. Always set to "2.0". |
| method | string | required | Name of the method to execute. Enter "slotsUpdatesUnsubscribe" here. |
| params | array | required | An array containing the subscription ID of the subscription to cancel. |
Example
{
"jsonrpc": "2.0",
"id": 1,
"method": "slotsUpdatesUnsubscribe",
"params": [0]
}
2. Response
Success Response
When the subscription is successfully cancelled, true is returned.
{
"jsonrpc": "2.0",
"result": true,
"id": 1
}
Error Response
If the unsubscribe fails, an error is returned.
{
"jsonrpc": "2.0",
"error": {
"code": -32000,
"message": "Invalid subscription ID"
},
"id": 1
}
3. How to Use
Connect to WebSocket Channel
wscat -c wss://api.mainnet-beta.solana.com
Subscribe to Slots Updates (First)
{
"jsonrpc": "2.0",
"id": 1,
"method": "slotsUpdatesSubscribe",
"params": []
}
Receive Subscription ID
{
"jsonrpc": "2.0",
"result": 0,
"id": 1
}
Unsubscribe
There are two ways to unsubscribe:
-
Close the connection: Press
Ctrl+Cin the terminal window to terminate the WebSocket connection, which automatically cancels all subscriptions. -
Cancel a specific subscription: Use slotsUpdatesUnsubscribe to cancel only a specific subscription while keeping the connection open.
{
"jsonrpc": "2.0",
"id": 2,
"method": "slotsUpdatesUnsubscribe",
"params": [0]
}
Confirm Unsubscribe
{
"jsonrpc": "2.0",
"result": true,
"id": 2
}