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

# blockSubscribe

> Subscribe to block notifications as blocks reach confirmed or finalized commitment.

Subscribe to receive notifications when a new block reaches `confirmed` or
`finalized` commitment.

<Info>
  **Source**

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

<Warning>
  **Unstable Method**

  Agave documents this as an [unstable RPC PubSub `blockSubscribe`
  subscription](https://github.com/anza-xyz/agave/blob/v4.3.2/validator/src/commands/run/args/pub_sub_config.rs#L72-L76).
  It is only available if the validator was started with
  `--rpc-pubsub-enable-block-subscription`, which also requires
  `--enable-rpc-transaction-history`.
</Warning>

<RequestExample>
  ```json WebSocket
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "blockSubscribe",
    "params": [
      {
        "mentionsAccountOrProgram": "LieKvPRE8XeX3Y2xVNHjKlpAScD12lYySBVQ4HqoJ5op"
      },
      {
        "commitment": "confirmed",
        "encoding": "base64",
        "transactionDetails": "full",
        "maxSupportedTransactionVersion": 0,
        "showRewards": true
      }
    ]
  }
  ```

  ```rs Rust
  use anyhow::Result;
  use futures::StreamExt;
  use solana_client::{
      nonblocking::pubsub_client::PubsubClient,
      rpc_config::{RpcBlockSubscribeConfig, RpcBlockSubscribeFilter},
  };
  use solana_commitment_config::CommitmentConfig;
  use solana_transaction_status_client_types::TransactionDetails;

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

      let filter = RpcBlockSubscribeFilter::MentionsAccountOrProgram(
          "LieKvPRE8XeX3Y2xVNHjKlpAScD12lYySBVQ4HqoJ5op".to_string(),
      );

      let config = RpcBlockSubscribeConfig {
          commitment: Some(CommitmentConfig::confirmed()),
          transaction_details: Some(TransactionDetails::Full),
          show_rewards: Some(true),
          max_supported_transaction_version: Some(0),
          ..Default::default()
      };

      let (mut notifications, unsubscribe) = pubsub_client
          .block_subscribe(filter, Some(config))
          .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

<ParamField body="filter" type="string | object" required>
  Filter describing which blocks should produce notifications.

  - `all` returns every matching block
  - `{ "mentionsAccountOrProgram": <pubkey> }` returns only blocks that contain a
    transaction mentioning the provided base-58 encoded address
</ParamField>

<ParamField body="config" type="object">
  Optional configuration object.

  <Expandable title="properties" defaultOpen>
    <ParamField body="commitment" type="string" default="finalized">
      Values: `confirmed`, `finalized`

      The commitment describes how finalized a block is at that point in time. See
      [Configuring State Commitment](/developers/docs/rpc#configuring-state-commitment).

      This method does not accept `processed`.
    </ParamField>

    <ParamField body="encoding" type="string" default="base64">
      Values: `binary`, `base58`, `base64`, `json`, `jsonParsed`

      Encoding format for each returned transaction.

      - `jsonParsed` uses program-specific parsers for
        `transaction.message.instructions` when available
      - If no parser is available, the RPC node falls back to standard JSON
        instruction fields
      - `binary` is a deprecated legacy alias for `base58`
    </ParamField>

    <ParamField body="transactionDetails" type="string" default="full">
      Values: `full`, `accounts`, `signatures`, `none`

      Level of transaction detail to return.

      - `accounts` returns signatures plus an annotated account list for each
        transaction
      - `signatures` omits full transaction objects and returns only block signatures
      - `none` omits both transaction objects and signatures
    </ParamField>

    <ParamField body="maxSupportedTransactionVersion" type="number">
      Highest transaction version your client supports. If omitted, only legacy
      transactions can be returned. If a matching block requires a higher transaction
      version, the notification populates `value.err` instead of returning block data.

      This field accepts any `u8`. Versioned transactions exposed by RPC use version
      `0`, and version `1` with the
      [v1 format](/developers/docs/core/transactions/versioned-transactions#v1-format) — set this
      to `1` to keep the subscription working on slots that carry v1 transactions.

      On a version error the notification arrives success-shaped with `block: null`
      and a populated `err`, and the subscription does **not** advance past that slot
      — it retries it indefinitely. Treat `block: null` with an error as a failure,
      never as an empty block.
    </ParamField>

    <ParamField body="showRewards" type="bool" default="false">
      Values: `true`, `false`

      Whether to populate the block `rewards` array. If omitted, the response omits
      rewards.
    </ParamField>
  </Expandable>
</ParamField>

## Result

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

## Notification format

Notifications are delivered as `blockNotification`.

The example below was captured from a subscription with
`transactionDetails: "full"`, `showRewards: true`, and
`maxSupportedTransactionVersion: 0`.

```json
{
  "jsonrpc": "2.0",
  "method": "blockNotification",
  "params": {
    "result": {
      "context": {
        "slot": 3537
      },
      "value": {
        "slot": 3537,
        "block": {
          "previousBlockhash": "J48KViVe4DpE5Xgkv5weChwBcsxzqmdZscUBE7eoeoCW",
          "blockhash": "51kbSjt8yVnmTWLzXSYyNS6KLuLhbFZuyoLJ36jz3Wpo",
          "parentSlot": 3536,
          "transactions": [
            {
              "transaction": [
                "AZTncP5v/zgbhG9gjGTB7U+lcT9ZqN70DXRGzCeoVqQ7ZOSUMDpfqiyIX2zKlyZefFYLLLkWJZfodF9VH6IgtggBAAEDB7ff3j2h8EhabhQ6/UsQ9Ff0qHRbDoFi8nyq1L7LuCrmza099j6XR/M+lQUi1PxTs6S67zfyGIc61J4Fgbx1gwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/WOyFspSu8OOPcxRVf/2cUIqYc/gtPOkSZH9Wx6m0dsBAgIAAQwCAAAAgJaYAAAAAAA=",
                "base64"
              ],
              "meta": {
                "err": null,
                "status": {
                  "Ok": null
                },
                "fee": 5000,
                "preBalances": [9959990000, 40000000, 1],
                "postBalances": [9949985000, 50000000, 1],
                "innerInstructions": [],
                "logMessages": [
                  "Program 11111111111111111111111111111111 invoke [1]",
                  "Program 11111111111111111111111111111111 success"
                ],
                "preTokenBalances": [],
                "postTokenBalances": [],
                "rewards": [],
                "loadedAddresses": {
                  "writable": [],
                  "readonly": []
                },
                "computeUnitsConsumed": 150,
                "costUnits": 1481
              },
              "version": "legacy"
            }
          ],
          "rewards": [
            {
              "pubkey": "BpdYYo2Vw1NVbzE2DqJxCX2xEfr42xvMYFU2dKd1CW57",
              "lamports": 7500,
              "postBalance": 499982330000,
              "rewardType": "Fee",
              "commission": null
            }
          ],
          "blockTime": 1774645307,
          "blockHeight": 3537
        },
        "err": null
      }
    },
    "subscription": 13
  }
}
```

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

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

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

  <Expandable title="properties" defaultOpen>
    <ResponseField name="result" type="object">
      Notification result object with `context` and `value`. For PubSub notifications,
      `context` includes `slot` and omits `apiVersion`.

      <Expandable title="properties">
        <ResponseField name="context" type="object">
          Context for the slot that triggered the notification.

          <Expandable title="properties">
            <ResponseField name="slot" type="u64">
              Slot associated with the notification.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="value" type="object">
          Block update payload for the subscribed filter.

          <Expandable title="properties">
            <ResponseField name="slot" type="u64">
              Slot of the block update.
            </ResponseField>

            <ResponseField name="block" type="object | null">
              Block data using the same structure documented for
              [getBlock](/developers/docs/rpc/http/getblock). When `err` is non-null, this may be `null`.
            </ResponseField>

            <ResponseField name="err" type="null | &#x22;BlockStoreError&#x22; | object">
              `null` on success, `"BlockStoreError"` if the block could not be loaded, or an
              object such as `{ "UnsupportedTransactionVersion": 0 }` when the block contains
              a transaction version above `maxSupportedTransactionVersion`.
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>

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