> ## 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.

# rootSubscribe

> Subscribe to notifications when the validator sets a new root slot.

<Info>
  **Source**

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

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

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

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

  const subscription = await rpc
    .rootNotifications()
    .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.onRootChange((root) => {
    console.log("New root:", root);
  });
  ```

  ```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.root_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
  [rootUnsubscribe](/developers/docs/rpc/websocket/rootunsubscribe).
</ResponseField>

## Notification format

Notifications are delivered as `rootNotification`.

```json
{
  "jsonrpc": "2.0",
  "method": "rootNotification",
  "params": {
    "result": 324,
    "subscription": 3
  }
}
```

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

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

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

  <Expandable title="properties" defaultOpen>
    <ResponseField name="result" type="u64">
      Latest rooted slot observed by the validator.
    </ResponseField>

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