---
id: HS0021
title: "Token account layout decoder"
url: https://carbium.sh/library/howsolana/token-account-layout-decoder
collection: How to use Solana
category: SPL tokens
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Token account layout decoder

One TypeScript file takes a token account address, fetches its raw data and decodes the fixed 165-byte layout by offset. It prints the holder wallet, the mint, the amount, the state and any delegate, then checks the holder against the node's parsed answer.

## Where the holder sits

A token account is a small account that the token program owns. Its data is a fixed binary layout, and the wallet that holds the tokens is one field inside it. That field is called `owner`, which causes most of the confusion: the account itself also has an owner at the Solana level, and that one is the token program. The holder you want is the `owner` field in the data, 32 bytes starting at offset 32.

The first 165 bytes are the same for the classic token program and for Token-2022. Token-2022 accounts that carry extensions keep more data after those 165 bytes, and the decoder below ignores it. Each field sits at a fixed offset, so you can read it without a schema library.

| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 32 | mint | The token this account counts. |
| 32 | 32 | owner | The holder: the wallet or program that may move the tokens. |
| 64 | 8 | amount | Balance in base units, an unsigned 64-bit integer, little endian. |
| 72 | 36 | delegate | A 4-byte flag, then a 32-byte address that may spend up to delegatedAmount. |
| 108 | 1 | state | 0 uninitialized, 1 initialized, 2 frozen. |
| 109 | 12 | isNative | A 4-byte flag, then the rent reserve for a wrapped SOL account. |
| 121 | 8 | delegatedAmount | How much the delegate may still spend. |
| 129 | 36 | closeAuthority | A 4-byte flag, then the address allowed to close the account. |

An optional field is a 4-byte flag followed by its payload. A flag of 0 means the payload is empty and 1 means it is set, and the token program refuses any other tag. The file reads the flag before it decodes a delegate or a close authority.

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24, which strips the types on load. The token account address is the first argument. With no argument the file reads a busy USDC vault, so the first run shows a full answer.

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

```ts
// HS0021 · Token account layout decoder
// https://carbium.sh/library/howsolana/token-account-layout-decoder
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
  getAddressDecoder,
  getBase64Encoder,
  isOffCurveAddress,
} 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 url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({ url, headers: { "x-api-key": key } }),
);

// Default: a USDC vault of Raydium's SOL-USDC pool, a token account with steady traffic.
const target = address(process.argv[2] ?? "HLmqeL62xR1QoZ1HKKbXRrdN1p3phKpxRMb2VVopvBBz");
const PROGRAMS: Record<string, string> = {
  TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA: "Token",
  TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb: "Token-2022",
};
const commitment = "confirmed";

const [rawRes, parsedRes] = await Promise.allSettled([
  rpc.getAccountInfo(target, { encoding: "base64", commitment }).send(),
  rpc.getAccountInfo(target, { encoding: "jsonParsed", commitment }).send(),
]);
if (rawRes.status === "rejected") {
  console.error(`raw read failed: ${rawRes.reason}`);
  process.exit(1);
}
const account = rawRes.value.value;
if (!account) {
  console.log(`${target}: no account at this address`);
  process.exit(0);
}
const program = PROGRAMS[account.owner];
const bytes = Uint8Array.from(getBase64Encoder().encode(account.data[0]));
// A token account is 165 bytes, or longer with account type byte 2 at offset 165 (Token-2022 extensions).
// 355 bytes is a multisig, which can hold a 2 at that offset.
const isTokenAccount =
  bytes.length === 165 || (bytes.length > 165 && bytes.length !== 355 && bytes[165] === 2);
if (!program || !isTokenAccount) {
  console.log(`${target} is not a token account (program ${account.owner}, ${bytes.length} bytes)`);
  process.exit(0);
}

// Fixed layout: mint 0, owner 32, amount 64, delegate 72, state 108, closeAuthority 129.
const view = new DataView(bytes.buffer);
const addr = getAddressDecoder();
const optional = (flagAt: number) =>
  view.getUint32(flagAt, true) === 1 ? addr.decode(bytes, flagAt + 4) : "none";
const states = ["uninitialized", "initialized", "frozen"];
const holder = addr.decode(bytes, 32);

console.log(`token account ${target} (${program} program)`);
console.log(`mint            ${addr.decode(bytes, 0)}`);
console.log(`holder (owner)  ${holder}`);
console.log(
  `holder kind     ${isOffCurveAddress(holder) ? "off curve (no private key, a program controls it)" : "on curve (keypair wallet)"}`,
);
console.log(`amount          ${view.getBigUint64(64, true)} base units`);
console.log(`state           ${states[bytes[108]] ?? bytes[108]}`);
console.log(`delegate        ${optional(72)}`);
console.log(`close authority ${optional(129)}`);

if (parsedRes.status === "fulfilled") {
  const data = parsedRes.value.value?.data as unknown as
    | { parsed?: { info?: { owner?: string } } }
    | undefined;
  console.log(`node's parsed owner matches: ${data?.parsed?.info?.owner === holder}`);
} else {
  console.error(`jsonParsed read failed: ${parsedRes.reason}`);
}
```

The file asks for the account twice at confirmed commitment. The first call uses `base64` encoding and returns the raw bytes. The decoder turns offsets into addresses with `getAddressDecoder` and reads the amount with `getBigUint64`, so the balance stays an exact integer. The second call uses `jsonParsed`, where the node does the same decoding, and the file compares the node's `owner` with its own. Both calls are settled together, so a failed `jsonParsed` read still leaves the decoded fields printed, followed by a line naming the failure.

## Reading the output

For a token account a person opened, the holder line is that person's wallet. A wallet address on its own holds SOL, and each token it owns lives in separate token accounts that name the wallet in this field.

Pool vaults, escrows and program-controlled accounts hold tokens too, and their holder is a program derived address with no private key. The default account in the file is one of those: its holder is the pool's authority address, which a program controls and no person signs for. The layout cannot tell you which kind of address you have, so the file asks kit's `isOffCurveAddress`. An address off the ed25519 curve has no private key and a program controls it, and an address on the curve is a keypair wallet. Reading the holder's owner program would mislead here, because a derived address that holds lamports is system-owned like any wallet, and one with no lamports returns null.

The amount is in base units. Divide by 10 to the power of the mint's decimals only for display, and keep the integer for arithmetic. [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) covers reading the scaled figure from the node and why a float loses digits.

## On Carbium

`getAccountInfo` is an account read and costs 10 cells. [Account reads](https://carbium.sh/docs#rpc) are allowed at 0.5 per second on Free, 15 on Dev, 50 on Business and 400 on Pro. A class absorbs [bursts](https://carbium.sh/docs#limits) up to 1,024 cells, so the two 10-cell reads in one run fit in a Free bucket back to back. A loop of reads past the burst is held to 0.5 per second on Free.

The file does not retry on a 429: it reports the failure and exits, which suits a one-off check.

For many token accounts, `getMultipleAccounts` takes up to 300 pubkeys at 10 cells each, and the 1024-cell burst caps a call at 100 pubkeys below Pro. The same offsets decode every account in the reply, so a holder report over a few hundred accounts is a loop around this file's decoding. A JSON-RPC batch of up to 100 calls is the other route.

## Where it ends

The decoder reads one token account at a time. It does not list the holders of a mint: `getTokenLargestAccounts` is not served on Carbium and answers `-32601`, an [error](https://carbium.sh/docs#errors) that a retry will not fix, and a full holder list needs an indexer you build or a program scan that app code should not run against the RPC.

It reads the account as it is now. A closed account returns `null`, and the file says so. One wallet may hold the same mint in several token accounts, so the holder field gives you the wallet for this account and says nothing about that wallet's whole balance of the token. Going the other way, from a wallet to its accounts, is `getTokenAccountsByOwner`.

An account that is not a token account fails the program and length checks and the file prints why. The file accepts exactly 165 bytes, or more than 165 bytes other than 355 with a 2 at offset 165, the account type byte of a Token-2022 account with extensions. A mint is 82 bytes, a multisig account is 355 bytes, a Token-2022 mint with extensions has a 1 at offset 165, and a wallet has no data, so all of them are caught early.

The offsets are for the token program's account layout. If you decode accounts of a program with its own layout, such as a pool or a lending position, those offsets do not apply, and you need that program's layout.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The output says `no account at this address`. | The account is closed or never existed. A closed token account returns null from getAccountInfo. Check that you passed a token account and not the wallet or the mint. |
| The output says the address is not a token account. | You passed a wallet, a mint, a multisig account or a program account. Find the token account first, for example with getTokenAccountsByOwner on the wallet, or take it from a transaction's account list. |
| The holder is an address you cannot find in any wallet app. | The account belongs to a program, such as a pool vault or an escrow. The holder kind line says `off curve` for these, which means the address has no private key. Do not read the holder's owner program to tell, since a derived address that holds lamports is system-owned too. |
| The last line says `node's parsed owner matches: false`. | The node's parsed owner differs from the holder the file decoded. Either the node parsed the account as something other than a token account, or the holder changed between the two reads, which a change of authority can do. Run the file again, and if it stays false, trust the node's answer and check the offsets. |

## Questions

### Is the owner field the same as the account's owner program?

No. The program that owns the account is the token program and shows up as `owner` on the getAccountInfo result itself. The holder wallet is the `owner` field inside the token account data, at offset 32.

### Can I get the holder without decoding the bytes myself?

Yes. Ask getAccountInfo for `jsonParsed` encoding and read `parsed.info.owner`. The file does both and compares them, so you can see the offsets agree with the node.

### How do I find who received a token transfer?

Read the transaction with getTransaction and look at `meta.postTokenBalances`, where each token account carries an `owner` that names its wallet. The instruction accounts name the receiving wallet only when the same transaction creates the associated account, so for a transfer into an existing token account you can also decode that destination account's `owner` field as above.

### Does the same layout work for Token-2022 accounts?

The first 165 bytes match, so mint, holder, amount and state decode at the same offsets. Extension data follows them and this file does not parse it.

### Do I need a private key for this?

No. The call reads public account data. The Carbium key only identifies your account to the RPC.

## Related

- [SPL token balance](https://carbium.sh/library/howsolana/spl-token-balance) (How to use Solana, HS0001)
- [Token holder tracker](https://carbium.sh/library/usecase/token-holder-tracker) (Use cases, UC0017)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
