---
id: HS0037
title: "Account notification fields"
url: https://carbium.sh/library/howsolana/account-notification-fields
collection: How to use Solana
category: WebSocket
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Account notification fields

One TypeScript file subscribes to an account over WebSocket, prints the first accountNotification and sets it beside a getAccountInfo read of the same account. The table names each field, its type and what to do with it.

## What one notification carries

`accountSubscribe` opens with one request and gets back a number, the subscription id. After that the server pushes a message every time the account changes at the commitment you asked for. Each push is a JSON-RPC notification with no `id` of its own: the `method` is `accountNotification` and everything useful sits under `params`.

| Field | Type | Meaning |
|---|---|---|
| `params.subscription` | number | The id the subscribe call returned. Match it when one socket carries several subscriptions, and pass it to `accountUnsubscribe` to stop. |
| `params.result.context.slot` | number | The slot in which this state was recorded. It is the value to store beside the data. |
| `params.result.value.lamports` | number | The balance in lamports. One SOL is 1,000,000,000 lamports. |
| `params.result.value.owner` | string | The address of the program that owns the account. Only that program can change its data. |
| `params.result.value.data` | array or object | The account bytes in the encoding you requested. With `base64` it is a two-item array: the encoded string, then the word `base64`. |
| `params.result.value.executable` | boolean | True when the account holds a program. |
| `params.result.value.rentEpoch` | number | A legacy field. Accounts that hold the rent-exempt minimum report the largest u64, 18446744073709551615. |
| `params.result.value.space` | number | The length of the data in bytes, before encoding. |

Each push carries the whole account. If a program writes one byte, you receive all of its data again with the current lamports. To learn what changed, keep the previous message and compare.

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24. The address is an optional argument. The default is the Clock sysvar, a 40-byte account the runtime rewrites every slot, so the first notification arrives within a moment.

`main.ts` (run: `node main.ts [address]`)

```ts
// HS0037 · Account notification fields
// https://carbium.sh/library/howsolana/account-notification-fields
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
} from "@solana/kit";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
const rpcUrl = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const wsUrl = process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh";
const target = process.argv[2] ?? "SysvarC1ock11111111111111111111111111111111";
const options = { encoding: "base64", commitment: "confirmed" } as const;

const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({ url: rpcUrl, headers: { "x-api-key": key } }),
);

// The same fields over HTTP, as a baseline for the pushed message.
try {
  const { context, value } = await rpc.getAccountInfo(address(target), options).send();
  if (value === null) console.log("getAccountInfo: account does not exist");
  else {
    console.log(
      `getAccountInfo slot=${context.slot} lamports=${value.lamports} owner=${value.owner} ` +
        `executable=${value.executable} space=${value.space} data=${value.data[1]}:${Buffer.from(value.data[0], "base64").length} bytes`,
    );
  }
} catch (e) {
  console.error(`getAccountInfo failed: ${e}`);
}

const ws = new WebSocket(`${wsUrl}?api-key=${encodeURIComponent(key)}`);
const timer = setTimeout(() => {
  console.log("no change to the account in 20 s");
  ws.close();
}, 20_000);

ws.addEventListener("open", () => {
  ws.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "accountSubscribe", params: [target, options] }));
});

ws.addEventListener("message", (event) => {
  const msg = JSON.parse(String(event.data));
  if (msg.error) {
    clearTimeout(timer);
    console.error(`subscribe failed: ${msg.error.code} ${msg.error.message}`);
    ws.close();
  } else if (msg.id === 1) {
    console.log(`subscribed, subscription id ${msg.result}`);
  } else if (msg.method === "accountNotification") {
    clearTimeout(timer);
    const { subscription, result } = msg.params;
    const { context, value } = result;
    console.log(
      `accountNotification subscription=${subscription} slot=${context.slot} lamports=${value.lamports} ` +
        `owner=${value.owner} executable=${value.executable} space=${value.space} ` +
        `data=${value.data[1]}:${Buffer.from(value.data[0], "base64").length} bytes`,
    );
    ws.send(JSON.stringify({ jsonrpc: "2.0", id: 2, method: "accountUnsubscribe", params: [subscription] }));
    ws.close();
  }
});

ws.addEventListener("error", () => {
  clearTimeout(timer);
  console.error("WebSocket error");
});
ws.addEventListener("close", () => clearTimeout(timer));
```

The file first calls `getAccountInfo` at `confirmed` with `base64` encoding and prints its `context.slot`, lamports, owner, `space` and data length. That gives you the same fields in the shape the HTTP method returns. Then it opens the socket, sends the `accountSubscribe` request with the same encoding and commitment, and prints the first `accountNotification`. It unsubscribes and closes after that message, or after 20 seconds with no change.

## Reading the output

The first line is the HTTP read, the second confirms the subscription, and the third is the pushed message. The two slots will differ, because the push arrives later and carries a slot newer than the read. Lamports, owner and `space` match as long as nothing wrote to the account in between.

Check the second item of `data` for the encoding name, then decode the first. For a `base64` array, `value.data[0]` is the payload to decode with `Buffer.from(text, "base64")`. The file prints `space` next to the decoded length so you can see the two agree.

The `rentEpoch` value is 18446744073709551615 for most accounts today. A plain `JSON.parse` turns that into a float and rounds it, so a log line shows 18446744073709552000. Treat the field as opaque unless you parse it with a bigint-aware reader.

> A notification means the account was written in that slot, and a write can leave the bytes the same. Compare the data before you treat a message as a change.

## The shape of data

The options object on the subscribe call takes `encoding` and `commitment`, and the encoding changes only the `data` field. Under `base64`, `base64+zstd` and `base58`, `data` is a two-item array: the encoded string, then the encoding name. Under `jsonParsed` it is an object when the node can decode the account type, and any other account falls back to a `base64` array, so check the shape of `data` before you read inside it. For the commitment choice, see [Solana commitment levels](https://carbium.sh/library/howsolana/solana-commitment-levels).

## On Carbium

The WebSocket endpoint is `wss://services.carbium.sh` with [the key in the URL](https://carbium.sh/docs#auth) as `?api-key=`, and the HTTP read goes to `https://services.carbium.sh`. Both addresses can be overridden with environment variables in the file.

On the [websocket](https://carbium.sh/docs#websocket) endpoint, `accountSubscribe` sends account state on change for streamed accounts. A plain SOL wallet sends nothing. To follow a wallet, subscribe with `logsSubscribe` using a mention of the address and read the balance again with `getBalance` when a log arrives. [Wallet activity tracker](https://carbium.sh/library/blockchainideas/wallet-activity-tracker) builds that pattern.

[Opening an account subscription](https://carbium.sh/docs#limits) costs 25 credits, the middle weight of the three prices (5, 25 and 200) that depend on the filter. After that each MiB the server sends costs 20 credits. A refused subscription costs nothing, and an `accountSubscribe` that never received a notification is refunded when it closes. Free carries 5 sockets, and the plan caps connections and subscriptions per account.

`getAccountInfo` is an account read at 10 cells per call. Free allows 0.5 of them per second, Dev 15, Business 50 and Pro 400. One call at the start of the file fits inside the burst allowance of 1,024 cells on any plan.

## Where it ends

Subscribing sends nothing until the account's next write, so read the account first, as the file does, and compare `context.slot` on each push.

The socket carries messages in order for one subscription, but nothing guarantees one message for each slot. Two writes in a slot can arrive as one push with the final state. A slot notified at `processed` can also end up skipped when its fork is dropped, so a fast display needs a way to step back.

The stream does not replay. A message sent while your socket was down is gone, and the first push after you reconnect carries the account as of its next write. Read the account again when you resubscribe.

The file waits for one message and exits. A long-running watcher needs a reconnect loop, a resubscribe after each drop and a heartbeat check of its own.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| No notification arrives for a plain wallet address. | accountSubscribe sends nothing for a plain SOL wallet. Subscribe to logsSubscribe with a mention of the address and read getBalance when a log arrives. |
| The file prints WebSocket error and no subscription id. | The handshake is refused with 401 when the key is unknown or cut short. Attach the whole key in the ?api-key= part of the URL and check that CARBIUM_KEY is set in the shell that runs the file. |
| The sixth socket on a Free account is refused. | Free carries 5 sockets for the whole account. Close one, put several subscriptions on one socket, or move to a plan with more connections. |
| The data field decodes to the wrong length. | Decode by the second item of the array. A base64 string needs a base64 decoder, a base58 string needs a base58 decoder, and base64+zstd needs decompression after decoding. Compare the result with the space field. |
| rentEpoch prints as 18446744073709552000. | JSON.parse read a u64 as a float. Leave the field alone, or parse the message with a reader that keeps big integers. |
| Data arrives as a base64 array after you asked for jsonParsed. | The node decodes only the account types it knows, and any other account falls back to base64. Check whether data is an array, and if it is, decode the first item with the base64 decoder. |

## Questions

### Does the notification show what changed in the account?

No. It carries the full account after the write. Keep the previous message and compare the data bytes or the lamports to find the change.

### Why is context.slot different from the slot of my own read?

They answer from different moments. The read answers from the view at the time you called it, and the push carries the slot in which the write was recorded, which is newer.

### Can I get several accounts on one socket?

Yes. Send one accountSubscribe per address on the same connection and match each push to its subscription field. Each subscription is priced on its own.

### How do I tell which subscription a push belongs to after a reconnect?

A new socket starts with new subscription ids, so the old ones mean nothing. Resubscribe each address, store the id each reply returns against its address, and match every push to that table.

## Related

- [Solana commitment levels](https://carbium.sh/library/howsolana/solana-commitment-levels) (How to use Solana, HS0003)
- [Wallet activity tracker](https://carbium.sh/library/blockchainideas/wallet-activity-tracker) (Blockchain ideas, BI0005)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
