> For the complete documentation index, see [llms.txt](https://docs.triton.one/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.triton.one/solana/rpc-methods/real-time-streaming/whirligig-websocket/accountsubscribe.md).

# accountSubscribe

Subscribe to changes in an account's lamports or data over WebSocket, with commitment, encoding, and dataSlice options.

## Request

{% tabs %}
{% tab title="wscat" %}

```bash
# npm install -g wscat
wscat -c "wss://<your-endpoint>.mainnet.rpcpool.com/<your-token>" -w -1 \
  -x '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "accountSubscribe",
  "params": [
    "CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12",
    {
      "encoding": "jsonParsed",
      "commitment": "finalized"
    }
  ]
}'
```

{% endtab %}

{% tab title="Kit" %}

```typescript
import { address, createSolanaRpcSubscriptions } from "@solana/kit";

const rpc = createSolanaRpcSubscriptions("wss://<your-endpoint>.mainnet.rpcpool.com/<your-token>");

const subscription = await rpc
  .accountNotifications(
    address("So11111111111111111111111111111111111111112"),
    {
      encoding: "jsonParsed",
      commitment: "finalized"
    }
  )
  .subscribe({ abortSignal: AbortSignal.timeout(50_000) });

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

{% endtab %}

{% tab title="web3.js" %}

```typescript
import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection("https://<your-endpoint>.mainnet.rpcpool.com/<your-token>", {
  commitment: "confirmed",
  wsEndpoint: "wss://<your-endpoint>.mainnet.rpcpool.com/<your-token>",
});

const publicKey = new PublicKey("CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12");

const subscriptionId = connection.onAccountChange(
  publicKey,
  (accountInfo, context) => {
    console.log("Account changed:", accountInfo);
    console.log("Context:", context);
  },
  "finalized"
);
```

{% endtab %}

{% tab title="Rust" %}

```rust
// Cargo.toml: anyhow = "1", futures = "0.3", solana-client = "~4.4",
// solana-commitment-config = "3", solana-sdk = "5", tokio = { version = "1", features = ["full"] }.
// solana-client 4.4 takes solana-sdk 5.x types. Requires Rust 1.98.1 or newer (solana-client 4.4).
use anyhow::Result;
use futures::StreamExt;
use solana_client::{nonblocking::pubsub_client::PubsubClient, rpc_config::RpcAccountInfoConfig};
use solana_commitment_config::CommitmentConfig;
use solana_sdk::pubkey::Pubkey;

#[tokio::main]
async fn main() -> Result<()> {
    let pubsub_client = PubsubClient::new("wss://<your-endpoint>.mainnet.rpcpool.com/<your-token>").await?;

    // using WSOL address
    let pubkey = Pubkey::from_str_const(&"So11111111111111111111111111111111111111112");

    let config = RpcAccountInfoConfig {
        commitment: Some(CommitmentConfig::confirmed()),
        encoding: None,
        data_slice: None,
        min_context_slot: None,
    };

    let (mut notifications, unsubscribe) = pubsub_client
        .account_subscribe(&pubkey, Some(config))
        .await?;

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

    unsubscribe().await;

    Ok(())
}
```

{% endtab %}
{% endtabs %}

In Rust, [`PubsubClient::account_subscribe`](https://docs.rs/solana-pubsub-client/latest/solana_pubsub_client/nonblocking/pubsub_client/struct.PubsubClient.html#method.account_subscribe) in the `solana-pubsub-client` crate sends this request.

## Parameters

**`0`** · string · required

Account Pubkey, as base-58 encoded string

**`1`** · object

Optional configuration object.

**`commitment`** · string · default `finalized`

Values: `processed`, `confirmed`, `finalized` The commitment describes how finalized a block is at that point in time. See [Configuring State Commitment](https://solana.com/docs/rpc#configuring-state-commitment).

**`encoding`** · string · default `binary`

Values: `base58`, `base64`, `base64+zstd`, `binary`, `jsonParsed` Encoding format for account data.

* `base58` is slow.
* `jsonParsed` attempts to use program-specific parsers to return more human-readable account state data.
* If `jsonParsed` is requested but no parser is available, the RPC node falls back to `[data, "base64"]`.
* `binary` is a deprecated legacy alias for base58 data returned as a plain string.

**`dataSlice`** · object

Request a slice of the account's data.

| Field    | Type    | Description                                           |
| -------- | ------- | ----------------------------------------------------- |
| `offset` | `usize` | Byte offset from which to start reading account data. |
| `length` | `usize` | Number of bytes to return.                            |

{% hint style="info" %}
Data slicing is only available for `base58`, `base64`, `base64+zstd`, and `binary` encodings.
{% endhint %}

{% hint style="info" %}
`base58` and `binary` use base-58 encoding. If the selected payload is more than 128 bytes after slicing, the account data is replaced by the string `error: data too large for bs58 encoding` (the first element of the `data` array for `base58`, the whole `data` value for `binary`). Use `base64` for larger accounts.
{% endhint %}

{% hint style="info" %}
`accountSubscribe` accepts the same config fields as [getAccountInfo](https://solana.com/docs/rpc/http/getaccountinfo), but WebSocket subscriptions currently ignore `minContextSlot`.
{% endhint %}

## Response

```json
{
  "jsonrpc": "2.0",
  "result": 23784,
  "id": 1
}
```

## Result

Subscription id. Pass this to [accountUnsubscribe](/solana/rpc-methods/real-time-streaming/whirligig-websocket/accountunsubscribe.md).

***

*Adapted from the* [*Solana `accountSubscribe` reference*](https://solana.com/docs/rpc/websocket/accountsubscribe)*, maintained by the Solana Foundation.*

***

<i class="fa-life-ring">:life-ring:</i> Contact support by clicking the chat icon in your [customer dashboard](https://customers.triton.one)\ <i class="fa-briefcase">:briefcase:</i> Sales questions? [Contact us](https://triton.one/contact)\ <i class="fa-sparkles">:sparkles:</i> AI agent? Read [llms.txt](https://docs.triton.one/llms.txt)\ <i class="fa-rss">:rss:</i> Follow updates: [Blog](https://blog.triton.one) · [X](https://x.com/triton_one) · [YouTube](https://www.youtube.com/@triton_one_ltd) · [Telegram](https://t.me/tritonone) · [GitHub](https://github.com/rpcpool)
