# accountSubscribe

> Emits a notification each time a single account's lamports or data change.

Source: https://docs.constant-k.com/rpc/websocket/accountsubscribe/

`accountSubscribe` opens a live feed for one account as an alternative to polling `getAccountInfo`. Each time the account's data or lamport balance changes at or above the requested commitment, constant-k's node emits one `accountNotification` carrying the account's new state and the slot the change landed in.

`encoding` controls how the `data` field is serialized in each notification, `dataSlice` shrinks the payload to a byte window for part of a large account, and `commitment` trades notification latency against the chance of the change being rolled back. The stream stays open until `accountUnsubscribe` is called or the socket closes.

- Transport: WebSocket, JSON-RPC 2.0 over `wss://ws-newyork.constant-k.com:1337/ws?api-key=YOUR_API_KEY`
- Category: Subscriptions
- Availability: Operator and above

## Parameters

`params` is a positional JSON array, in this order:

- `pubkey` (string, required): Base58-encoded public key of the account to watch.
- `config` (object, optional): Optional subscription settings.
  - `encoding` (string, optional, one of `base58`, `base64`, `base64+zstd`, `jsonParsed`, default `"base58"`): Format for the returned account `data`. `base58` is the legacy default (also accepted under its old name `binary`) and is slow for large accounts; `jsonParsed` asks the node to run a program-specific parser and silently falls back to `base64` when no parser exists for the account's owner.
  - `commitment` (string, optional, one of `processed`, `confirmed`, `finalized`, default `"finalized"`): How settled the account/transaction state must be before the node acts on it. `processed` is fastest and can roll back; `finalized` is slowest and never rolls back.
  - `dataSlice` (object | null, optional): Returns only a byte range of `data` instead of the whole payload. Not compatible with `jsonParsed` encoding.
    - `offset` (integer, required, min 0): Byte offset to start the slice at.
    - `length` (integer, required, min 0): Number of bytes to return.
  - `minContextSlot` (integer, optional, min 0): Minimum slot the node must have reached before it will process the subscription. Accepted for parity with the HTTP `RpcAccountInfoConfig` struct; Agave's pubsub handler does not currently gate notifications on it.

## Result

- `result` (integer, optional): The subscription id, returned once in the initial RPC response. Passed to `accountUnsubscribe`, it cancels the stream.

## Notifications

Updates arrive as `accountNotification` messages. `result.context.slot` is the slot the change was observed in; `result.value` is the account's new state, shaped like the `value` of `getAccountInfo` (`lamports`, `data`, `owner`, `executable`, `rentEpoch`, `space`), with `data` encoded per the requested `encoding`.

- `params.result` (object, optional)
  - `context` (object, optional): Response context, including the slot the data was read at.
    - `slot` (integer, optional): Slot number this applies to.
  - `value` (object, optional): The requested data; see the fields below.
    - `lamports` (integer, optional): Account balance, in lamports.
    - `data` (any, optional): Account data, shaped by the requested `encoding` (an object for `jsonParsed`, a `[string, encoding]` tuple otherwise).
    - `owner` (string, optional): Base58 address of the program (or, for a token account, the wallet) that owns this account.
    - `executable` (boolean, optional): Whether this account is a program.
    - `rentEpoch` (integer, optional): Legacy rent-exemption epoch; not meaningful for accounts created after rent-exempt minimums became mandatory.
    - `space` (integer, optional): Size of the account's data, in bytes.

## Unsubscribe

`accountUnsubscribe`, called with the subscription id, returns `true` once the subscription is removed.

## Example: Subscribe to the Clock sysvar

Request (send after connecting):

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "accountSubscribe",
  "params": [
    "SysvarC1ock11111111111111111111111111111111",
    {
      "encoding": "jsonParsed",
      "commitment": "confirmed"
    }
  ]
}
```

Response:

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

Notification:

```json
{
  "jsonrpc": "2.0",
  "method": "accountNotification",
  "params": {
    "result": {
      "context": {
        "slot": 447946417
      },
      "value": {
        "lamports": 1169280,
        "data": {
          "program": "sysvar",
          "parsed": {
            "info": {
              "epoch": 1036,
              "epochStartTimestamp": 1789571004,
              "leaderScheduleEpoch": 1037,
              "slot": 447946417,
              "unixTimestamp": 1789696068
            },
            "type": "clock"
          },
          "space": 40
        },
        "owner": "Sysvar1111111111111111111111111111111111111",
        "executable": false,
        "rentEpoch": 18446744073709552000,
        "space": 40
      }
    },
    "subscription": 26917684
  }
}
```

## Notes

- WebSocket access is included on the Operator plan and above; it is not available on Free.
- Concurrent connections are capped per API key: 10 on Operator, 50 on Blade Runner, 100 on Nexus.
- Subscribe and unsubscribe calls draw from the same global per-plan request-rate limit as HTTP calls: 50 req/s on Operator, 200 req/s on Blade Runner, 500 req/s on Nexus.
- Only subscription methods (the `*Subscribe` / `*Unsubscribe` family) are accepted on the WebSocket endpoint; standard request/response RPC methods must go over HTTPS instead.
- A `getHealth` request sent over the open socket on a regular interval serves as a keepalive; connections that go quiet can be dropped by intermediate load balancers.
- Each region has its own WebSocket hostname, for example `wss://ws-newyork.constant-k.com:1337/ws?api-key=YOUR_API_KEY`; every region is listed on the Endpoints page.
- Captured live from `wss://api.mainnet-beta.solana.com` against the Clock sysvar, which updates every slot, useful for confirming a subscription is alive.

