Skip to main content

slotsUpdatesSubscribe

The Solana slotsUpdatesSubscribe method creates a subscription to receive real-time notifications for various updates that occur in each slot as a validator processes them.

Usage Notes
  • 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.
  • 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.
This subscription may be unstable.
  • This subscription receives various updates occurring in each slot, which can result in very frequent notifications.
  • The subscription format may change in the future and may not always be supported.

1. Request

Parameters

The slot updates subscription request has the following parameters.

ParameterTypeRequiredDescription
idinteger or stringrequiredUnique identifier for the request. Used by the client to match requests with responses.
jsonrpcstringrequiredJSON-RPC protocol version. Always set to "2.0".
methodstringrequiredName of the method to execute. Enter "slotsUpdatesSubscribe" here.
paramsarrayrequiredNo additional parameters are required for slot updates subscription. Use an empty array.

Example

{
"jsonrpc": "2.0",
"id": 1,
"method": "slotsUpdatesSubscribe",
"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 slotsUpdatesUnsubscribe method.

Notifications

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

Notification format:

FieldTypeDescription
errstring | undefinedError message. Present only when the update type is "dead".
parentu64 | undefinedParent slot. Present only when the update type is "createdBank".
slotu64The newly updated slot number.
statsobject | undefinedStatistics information. Present only when the update type is "frozen".
stats.maxTransactionsPerEntryu64 | undefinedMaximum number of transactions per entry.
stats.numFailedTransactionsu64 | undefinedNumber of failed transactions.
stats.numSuccessfulTransactionsu64 | undefinedNumber of successful transactions.
stats.numTransactionEntriesu64 | undefinedNumber of transaction entries.
timestampi64Unix timestamp of the update.
typestringUpdate type. Returns one of the following values: "firstShredReceived", "completed", "createdBank", "frozen", "dead", "optimisticConfirmation", "root"

Slots Updates Notification Example

{
"jsonrpc": "2.0",
"method": "slotsUpdatesNotification",
"params": {
"result": {
"parent": 75,
"slot": 76,
"timestamp": 1625081266243,
"type": "optimisticConfirmation"
},
"subscription": 0
}
}

3. How to Use

Connect to WebSocket Channel

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

Subscribe to Slots Updates

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

Receive Notifications

  • Initial response: subscription ID is returned
  • Subsequently: a "slotsUpdatesNotification" event is received whenever a slot update occurs

Unsubscribe

There are two ways to unsubscribe:

  1. Close the connection: Press Ctrl+C in the terminal window to terminate the WebSocket connection, which automatically cancels all subscriptions.

  2. Cancel a specific subscription: Use slotsUpdatesUnsubscribe to cancel only a specific subscription while keeping the connection open.

Unsubscribe request:

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

Response after unsubscribing:

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