slotsUpdatesUnsubscribe

The slotsUpdatesUnsubscribe method cancels a slot updates subscription created by slotsUpdatesSubscribe, stopping further slot update notifications.


1. Request

Parameters

The slot updates unsubscribe request accepts the following parameters.

ParameterTypeRequiredDescription
idinteger or stringrequiredA unique identifier for the request, used by the client to match requests with responses.
jsonrpcstringrequiredThe JSON-RPC protocol version. Always set to "2.0".
methodstringrequiredThe name of the method to invoke. Set to "slotsUpdatesUnsubscribe".
paramsarrayrequiredAn array containing the subscription ID to cancel.

Example

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "slotsUpdatesUnsubscribe",
  "params": [0]
}

2. Response

Success Response

Returns true when the subscription is successfully cancelled.

{
  "jsonrpc": "2.0",
  "result": true,
  "id": 1
}

Error Response

Returns an error if the unsubscribe request fails.

{
  "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 cancel a subscription:

  1. Close the connection: Press CTRL+C in the terminal to close the WebSocket connection. All active subscriptions are automatically cancelled.

  2. Cancel a specific subscription: Use slotsUpdatesUnsubscribe to cancel 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
}