Skip to content
Alchemy Logo

slotSubscribe

Subscribe to notifications when the Solana validator processes a new slot.

The slotSubscribe method opens a stream that emits a notification each time the validator processes a new slot. Pair it with slotUnsubscribe to stop receiving notifications.

  • None

// initiate websocket stream first
wscat -c wss://solana-mainnet.g.alchemy.com/v2/<-- ALCHEMY APP API KEY -->
 
// then call subscription
{"jsonrpc":"2.0","id":1,"method":"slotSubscribe"}

// subscribe response
{"jsonrpc":"2.0","result":0,"id":1}
 
// notification
{
  "jsonrpc": "2.0",
  "method": "slotNotification",
  "params": {
    "result": {
      "parent": 75,
      "root": 42,
      "slot": 76
    },
    "subscription": 0
  }
}

Use slotUnsubscribe with the subscription id returned by slotSubscribe to cancel the stream.

  • subscription_id: number - The subscription id to cancel.
{"jsonrpc":"2.0","id":1,"method":"slotUnsubscribe","params":[subscription_id]}
{"jsonrpc":"2.0","result":true,"id":1}

When using @solana/web3.js, call connection.removeSlotChangeListener(subscriptionId) instead of sending the raw JSON-RPC request.

Was this page helpful?