> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# slotSubscribe

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

<Info>
  **Source**

  [`slot_subscribe`](https://github.com/anza-xyz/agave/blob/v4.3.2/rpc/src/rpc_pubsub.rs#L532)
</Info>

<RequestExample>
  ```json WebSocket
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "slotSubscribe"
  }
  ```

  ```ts Kit
  import { createSolanaRpcSubscriptions } from "@solana/kit";

  const rpc = createSolanaRpcSubscriptions("wss://api.devnet.solana.com");

  const subscription = await rpc
    .slotNotifications()
    .subscribe({ abortSignal: AbortSignal.timeout(5_000) });

  for await (const notification of subscription) {
    console.log(notification);
  }
  ```

  ```ts web3.js
  import { Connection, clusterApiUrl } from "@solana/web3.js";

  const connection = new Connection(clusterApiUrl("devnet"), "confirmed");

  const subscriptionId = connection.onSlotChange((slotInfo) => {
    console.log("Slot info:", slotInfo);
  });
  ```

  ```rs Rust
  use anyhow::Result;
  use futures::StreamExt;
  use solana_client::nonblocking::pubsub_client::PubsubClient;

  #[tokio::main]
  async fn main() -> Result<()> {
      let pubsub_client = PubsubClient::new("wss://api.devnet.solana.com/").await?;

      let (mut notifications, unsubscribe) = pubsub_client.slot_subscribe().await?;

      while let Some(notification) = notifications.next().await {
          println!("{:?}", notification);
      }

      unsubscribe().await;

      Ok(())
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Response
  {
    "jsonrpc": "2.0",
    "result": 0,
    "id": 1
  }
  ```
</ResponseExample>

## Parameters

**None**

## Result

<ResponseField name="result" type="integer">
  Subscription id. Pass this to
  [slotUnsubscribe](/developers/docs/rpc/websocket/slotunsubscribe).
</ResponseField>

## Notification format

Notifications are delivered as `slotNotification`.

```json
{
  "jsonrpc": "2.0",
  "method": "slotNotification",
  "params": {
    "result": {
      "slot": 373,
      "parent": 372,
      "root": 341
    },
    "subscription": 5
  }
}
```

<ResponseField name="jsonrpc" type="string">
  Always `"2.0"`.
</ResponseField>

<ResponseField name="method" type="string">
  Always `"slotNotification"`.
</ResponseField>

<ResponseField name="params" type="object">
  Notification wrapper with the slot payload and the subscription id.

  <Expandable title="properties" defaultOpen>
    <ResponseField name="result" type="object">
      Raw slot information for the newly processed slot. This payload is serialized
      directly and does not include `context` and `value`.

      <Expandable title="properties">
        <ResponseField name="slot" type="u64">
          The newly processed slot.
        </ResponseField>

        <ResponseField name="parent" type="u64">
          The parent of `slot`.
        </ResponseField>

        <ResponseField name="root" type="u64">
          The current root slot when the notification was emitted.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="subscription" type="integer">
      Subscription id that produced this notification.
    </ResponseField>
  </Expandable>
</ResponseField>
