slotSubscribe

The slotSubscribe method creates a subscription that delivers real-time notifications each time a validator processes a slot.


1. Request

Parameters

The slot subscription 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 "slotSubscribe".
paramsarrayrequiredNo additional parameters are required for slot subscription. Use an empty array.

Example

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

2. Response

Subscription Response

On success, the server returns a subscription ID.

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

This subscription ID is required when calling the slotUnsubscribe method.

Notifications

Once the subscription is active, the server pushes a notification each time a validator processes a slot.

Notification format:

FieldTypeDescription
parentu64The parent slot number
rootu64The current root slot number
slotu64The newly processed slot number

Slot Notification Example

{
  "jsonrpc": "2.0",
  "method": "slotNotification",
  "params": {
    "result": {
      "parent": 75,
      "root": 44,
      "slot": 76
    },
    "subscription": 0
  }
}

3. How to Use

Connect to WebSocket Channel

wscat -c wss://api.mainnet-beta.solana.com

Subscribe to Slots

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

Receive Notifications

  • Initial response: a subscription ID is returned.
  • Subsequent: a "slotNotification" event is received each time a validator processes a slot.

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 slotUnsubscribe to cancel a specific subscription while keeping the connection open.

Unsubscribe request:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "slotUnsubscribe",
  "params": [0]
}

Response after unsubscribing:

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