---
title: slotSubscribe
description: Subscribe to notifications when the validator processes a new slot.
url: /docs/rpc/websocket/slotsubscribe
type: reference
hideTableOfContents: true
---

Subscribe to notifications when the validator processes a new slot.

<Callout type="info" title="Source">
  [`slot_subscribe`](https://github.com/anza-xyz/agave/blob/v3.1.8/rpc/src/rpc_pubsub.rs#L529)
</Callout>

<APIMethod>

```jsonc !!request curl
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "slotSubscribe"
}
```

```ts !!request title="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 !!request title="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 !!request title="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(())
}
```

### !params

**None**

### !!result

```jsonc !response
{
  "jsonrpc": "2.0",
  // !hover result
  "result": 0,
  "id": 1
}
```

!type integer

Subscription id. Pass this to
[slotUnsubscribe](/docs/rpc/websocket/slotunsubscribe).

</APIMethod>

### Notification format

Notifications are delivered as `slotNotification`.

<CodeReference>

```jsonc !!
{
  // !hover jsonrpc
  "jsonrpc": "2.0",
  // !hover method
  "method": "slotNotification",
  // !hover(1:8) params
  "params": {
    // !hover params.result
    "result": {
      // !hover params.result.slot
      "slot": 373,
      // !hover params.result.parent
      "parent": 372,
      // !hover params.result.root
      "root": 341
    },
    // !hover params.subscription
    "subscription": 5
  }
}
```

## !reference

### !! jsonrpc

!type string

Always `"2.0"`.

### !! method

!type string

Always `"slotNotification"`.

### !! params

!type object

Notification wrapper with the slot payload and the subscription id.

#### !! result

!type object

Raw slot information for the newly processed slot. This payload is serialized
directly and does not include `context` and `value`.

##### !! slot

!type u64

The newly processed slot.

##### !! parent

!type u64

The parent of `slot`.

##### !! root

!type u64

The current root slot when the notification was emitted.

#### !! subscription

!type integer

Subscription id that produced this notification.

</CodeReference>
