slotSubscribe
The Solana slotSubscribe method creates a subscription to receive real-time notifications whenever a validator processes a slot.
- Must be called via a WebSocket endpoint; HTTP is not supported.
- If the WebSocket connection is closed, subscriptions are automatically cancelled. You must re-subscribe upon reconnection.
- This subscription receives notifications every time a validator processes a slot, which can result in very frequent notifications.
- CU is consumed based on the amount of data subscribed, so it is recommended to use appropriate filtering options to subscribe only to the data you need.
1. Request
Parameters
The slot subscription 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 "slotSubscribe" here. |
| params | array | required | No additional parameters are required for slot subscription. Use an empty array. |
Example
{
"jsonrpc": "2.0",
"id": 1,
"method": "slotSubscribe",
"params": []
}
2. Response
Subscription Response
When the subscription is successfully created, a subscription ID is returned.
{
"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 every time a validator processes a slot.
Notification format:
| Field | Type | Description |
|---|---|---|
| parent | u64 | The parent slot number |
| root | u64 | The current root slot number |
| slot | u64 | The newly set slot value |
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: subscription ID is returned
- Subsequently: a "slotNotification" event is received every time a validator processes a slot
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 slotUnsubscribe to cancel only 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
}