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

# Hold a gated token as a custodian

> Take the custodian side of a gated token: derive the custody address, get it allowlisted, receive the asset, observe a freeze, and reconcile at a stated commitment level.

The [issuing tutorial](/developers/docs/tokenization/tutorials/issuing) builds
a gated token from the issuer's side. This one takes the custodian side, where
a custody system holds the asset for a client and has to handle what the issuer
does with its controls. It continues with the mint from
[gate the holders](/developers/docs/tokenization/tutorials/issuing/gate-the-holders),
so `$MINT` and `$LIST` should already be exported, on the same network.

<Info>
**Custodian-side and issuer-side steps**

The custodian-side steps read the custody account with `spl-token`, which is
part of the Solana CLI install. To read it from code as well, use the
`derive-ata` and `read-account` scripts in the Kit, Web3.js v3, or Rust project
from the issuing tutorial. The `spl-token` commands use `$RPC_URL` when it is
set and devnet otherwise. The issuer-side steps run the issuing tutorial's
scripts and are marked where they appear: in a real integration another party
runs them.
</Info>

<Steps titleSize="h2">

<Step title="Create the custody address">

A custodian holds the asset at an address it controls. Here a key file stands
in for whatever your key-management backend produces; see
[choosing a backend](/developers/docs/tools/keychain/choosing-a-backend) for
what that is in production. The custodian signs nothing in this tutorial, so it
needs no SOL.

```bash Terminal
solana-keygen new --no-bip39-passphrase --silent \
  --outfile ~/.config/solana/demo-custodian.json
export CUSTODIAN=$(solana-keygen pubkey ~/.config/solana/demo-custodian.json)
```

</Step>

<Step title="Derive the token account address before it exists">

The asset does not sit at your wallet address. It sits in an associated token
account derived from that wallet and the mint. Two addresses are involved:

- The **wallet** is what the issuer allowlists. That is the onboarding
  decision.
- The **associated token account** holds the balance, is what the issuer
  freezes, and is what your reconciliation reads.

The associated token address is deterministic, so you can compute it before
the account exists and set up monitoring and reconciliation ahead of the first
transfer. Save the script as `derive-ata.ts` (in Rust, `src/bin/derive-ata.rs`)
and run it with `$CUSTODIAN`.

<Tabs>
<Tab title="spl-token">
<div className="sol-tab-label">spl-token</div>

```bash
spl-token address --token $MINT --owner $CUSTODIAN --verbose \
  --url ${RPC_URL:-devnet}
```

<div className="sol-run" data-run="paths/assets/gated-token/derive-ata" data-tab="spl-token">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Deriving the custody token account before it exists</span></div>
<div className="sol-run-out">

```text Output
Wallet address: 6tUvc1Jco5iA8c1JKpjtLFwLvLSXTCfjtoYnnTazH7yH
Associated token address: EqM2po44bk4JqjMeyynvaGd7aFWquBgLmnyVgMHyt1GC
```

</div>
</div>

</Tab>
<Tab title="Kit">
<div className="sol-tab-label">Kit</div>

```ts
// npx tsx derive-ata.ts <wallet>
import { address } from "@solana/kit";
import {
  findAssociatedTokenPda,
  TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { arg, env } from "./common";

const owner = address(arg(1, "the custody wallet"));
// Deterministic: the address exists before the account does, so monitoring
// and reconciliation can be wired up ahead of the first transfer.
const [tokenAccount] = await findAssociatedTokenPda({
  mint: address(env("MINT")),
  owner,
  tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
console.log("Wallet address:", owner);
console.log("Associated token address:", tokenAccount);
```

<div className="sol-run" data-run="paths/assets/gated-token/derive-ata" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Deriving the custody token account before it exists</span></div>
<div className="sol-run-out">

```text Output
Wallet address: 6tUvc1Jco5iA8c1JKpjtLFwLvLSXTCfjtoYnnTazH7yH
Associated token address: EqM2po44bk4JqjMeyynvaGd7aFWquBgLmnyVgMHyt1GC
```

</div>
</div>

</Tab>
<Tab title="Web3.js v3">
<div className="sol-tab-label">Web3.js v3</div>

```ts
// npx tsx derive-ata.ts <wallet>
import {
  findAssociatedTokenPda,
  TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { addressOf, arg, env } from "./common";

const owner = addressOf(arg(1, "the custody wallet"));
// Deterministic: the address exists before the account does, so monitoring
// and reconciliation can be wired up ahead of the first transfer.
const [tokenAccount] = await findAssociatedTokenPda({
  mint: addressOf(env("MINT")),
  owner,
  tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
console.log("Wallet address:", owner);
console.log("Associated token address:", tokenAccount);
```

<div className="sol-run" data-run="paths/assets/gated-token/derive-ata" data-tab="Web3.js v3">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Deriving the custody token account before it exists</span></div>
<div className="sol-run-out">

```text Output
Wallet address: CYeEVDXLFbeMQH2Dhsiimpt5Q3Vw6Y4WDS4tpijN31q8
Associated token address: 3KvGzV1LtQ518hGUGG9zktuG6TA73gK6DFH4au2sGxWc
```

</div>
</div>

</Tab>
<Tab title="Rust">
<div className="sol-tab-label">Rust</div>

```rust
// cargo run --release --bin derive-ata -- <wallet>
use anyhow::Result;
use gated_token::{arg_pubkey, ata, env};

fn main() -> Result<()> {
    let owner = arg_pubkey(1, "the custody wallet")?;
    // Deterministic: the address exists before the account does, so
    // monitoring and reconciliation can be wired up ahead of the first transfer.
    println!("Wallet address: {owner}");
    println!("Associated token address: {}", ata(&env("MINT")?, &owner));
    Ok(())
}
```

<div className="sol-run" data-run="paths/assets/gated-token/derive-ata" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Deriving the custody token account before it exists</span></div>
<div className="sol-run-out">

```text Output
Wallet address: BeoQ6d1SXZqxpfL3dTQKKk9Bw278Z5yQYsUe2dQcHieE
Associated token address: B1JU1cH8dzag2XZ65NdTPnztMSH3yXMpgT2ZP45SnmaT
```

</div>
</div>

</Tab>
</Tabs>

Export the `Associated token address` it prints as `CUSTODY_ATA`; the reads
below use it:

```bash Terminal
export CUSTODY_ATA=<the associated token address>
```

If your platform rotates wallets per client or per deposit, each wallet needs allowlisting before it
can receive (see
[custody integration](/developers/docs/tokenization/custody/custody-integration)).

</Step>

<Step title="Get the address onto the allowlist">

Issuer side. You supply the wallet address, not the token account, and the
issuer records the onboarding decision with `allowlist-add`:

<CodeGroup>
```bash TypeScript
npx tsx allowlist-add.ts $CUSTODIAN
```

```bash Rust
cargo run --release --bin allowlist-add -- $CUSTODIAN
```
</CodeGroup>

</Step>

<Step title="Receive the asset">

Issuer side again: a mint of 500 to the custody address. The token account is
created and thawed in the same transaction, because the wallet is on the list.

<CodeGroup>
```bash TypeScript
npx tsx mint.ts $CUSTODIAN 500
```

```bash Rust
cargo run --release --bin mint -- $CUSTODIAN 500
```
</CodeGroup>

</Step>

<Step title="Confirm what you hold">

Back on the custodian side. Read the token account directly with `spl-token`:

```bash spl-token
spl-token display $CUSTODY_ATA --url ${RPC_URL:-devnet}
```

<div className="sol-run" data-run="paths/assets/gated-token/display-thawed" data-tab="spl-token">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account after the issuer mints 500</span></div>
<div className="sol-run-out">

```text Output

SPL Token Account
  Address: EqM2po44bk4JqjMeyynvaGd7aFWquBgLmnyVgMHyt1GC
  Program: TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
  Balance: 500
  Decimals: 6
  Mint: 8ComqBcog3Aig4hYN9PcCQHcK4rCCUhv7QoxUfrVVB66
  Owner: 6tUvc1Jco5iA8c1JKpjtLFwLvLSXTCfjtoYnnTazH7yH
  State: Initialized
  Delegation: (not set)
  Close authority: (not set)
Extensions:
  Immutable owner

* This token has a permanent delegate! 
  This means the mint may withdraw all funds from this account at any time.
  If this was not adequately disclosed to you, you may be dealing with a malicious mint.
```

</div>
</div>

To read it from code, use the `read-account` script from
[operate the token](/developers/docs/tokenization/tutorials/issuing/operate-the-token#offboard-a-holder),
run with `$CUSTODY_ATA`:

<Tabs>
<Tab title="Kit">
<div className="sol-tab-label">Kit</div>

```ts
// npx tsx read-account.ts <token account> [commitment]
import { address, type Commitment } from "@solana/kit";
import { AccountState, fetchToken } from "@solana-program/token-2022";
import { arg, rpc } from "./common";

const tokenAccount = address(arg(1, "the token account"));
// Read at a stated commitment level. Use "finalized" for anything that feeds
// a book of record; "confirmed" is enough for a display.
const commitment = (process.argv[3] ?? "confirmed") as Commitment;

const { data } = await fetchToken(rpc, tokenAccount, { commitment });
console.log("Mint:", data.mint);
console.log("Owner:", data.owner);
console.log("Balance (base units):", data.amount.toString());
console.log("State:", AccountState[data.state]);
```

<div className="sol-run" data-run="paths/assets/gated-token/read-thawed" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account after the issuer mints 500</span></div>
<div className="sol-run-out">

```text Output
Mint: 8ComqBcog3Aig4hYN9PcCQHcK4rCCUhv7QoxUfrVVB66
Owner: 6tUvc1Jco5iA8c1JKpjtLFwLvLSXTCfjtoYnnTazH7yH
Balance (base units): 500000000
State: Initialized
```

</div>
</div>

</Tab>
<Tab title="Web3.js v3">
<div className="sol-tab-label">Web3.js v3</div>

```ts
// npx tsx read-account.ts <token account> [commitment]
import { type Commitment, PublicKey } from "@solana/web3.js";
import { AccountState, getTokenDecoder } from "@solana-program/token-2022";
import { arg, connection } from "./common";

const tokenAccount = new PublicKey(arg(1, "the token account"));
// Read at a stated commitment level. Use "finalized" for anything that feeds
// a book of record; "confirmed" is enough for a display.
const commitment = (process.argv[3] ?? "confirmed") as Commitment;

const info = await connection.getAccountInfo(tokenAccount, commitment);
const data = getTokenDecoder().decode(info!.data);
console.log("Mint:", data.mint);
console.log("Owner:", data.owner);
console.log("Balance (base units):", data.amount.toString());
console.log("State:", AccountState[data.state]);
```

<div className="sol-run" data-run="paths/assets/gated-token/read-thawed" data-tab="Web3.js v3">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account after the issuer mints 500</span></div>
<div className="sol-run-out">

```text Output
Mint: 8xDpQoKEXGrtCm5JwseD2v7KHCNnXv8kQmm61Cjozn7o
Owner: CYeEVDXLFbeMQH2Dhsiimpt5Q3Vw6Y4WDS4tpijN31q8
Balance (base units): 500000000
State: Initialized
```

</div>
</div>

</Tab>
<Tab title="Rust">
<div className="sol-tab-label">Rust</div>

```rust
// cargo run --release --bin read-account -- <token account> [commitment]
use anyhow::{anyhow, Result};
use gated_token::{arg, arg_pubkey, rpc_with};
use solana_commitment_config::CommitmentConfig;
use spl_token_2022_interface::{
    extension::StateWithExtensions,
    state::{Account, AccountState},
};

#[tokio::main]
async fn main() -> Result<()> {
    let token_account = arg_pubkey(1, "the token account")?;
    // Read at a stated commitment level. Use "finalized" for anything that
    // feeds a book of record; "confirmed" is enough for a display.
    let commitment = match arg(2, "the commitment").as_deref() {
        Ok("finalized") => CommitmentConfig::finalized(),
        _ => CommitmentConfig::confirmed(),
    };
    let rpc = rpc_with(commitment);
    let account = rpc
        .get_account_with_commitment(&token_account, commitment)
        .await?
        .value
        .ok_or_else(|| anyhow!("{token_account} not found at {commitment:?}"))?;
    let state = StateWithExtensions::<Account>::unpack(&account.data)?.base;

    println!("Mint: {}", state.mint);
    println!("Owner: {}", state.owner);
    println!("Balance (base units): {}", state.amount);
    let label = if state.state == AccountState::Frozen {
        "Frozen"
    } else {
        "Initialized"
    };
    println!("State: {label}");
    Ok(())
}
```

<div className="sol-run" data-run="paths/assets/gated-token/read-thawed" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account after the issuer mints 500</span></div>
<div className="sol-run-out">

```text Output
Mint: 3zsS4p5aDBiqLmCynUBayqCM9WWR35jr51tT4maAT1P1
Owner: BeoQ6d1SXZqxpfL3dTQKKk9Bw278Z5yQYsUe2dQcHieE
Balance (base units): 500000000
State: Initialized
```

</div>
</div>

</Tab>
</Tabs>

Read two fields. **Balance** is the position. `spl-token` applies the mint's
six decimals and shows `Balance: 500`; the scripts print the raw amount in base
units, `500000000`. **State** is the field a custody system must handle:
`Initialized` means the account is thawed and usable, and `Frozen` means it is
not. If a custody system does not show this field, a failed withdrawal cannot
be explained from the account state.

The `spl-token display` output also warns that the mint has a permanent
delegate, which can move the balance out of the account at any time. A
custodian needs that disclosed by the issuer, and a category for such movements
in its reconciliation.

</Step>

<Step title="Observe a freeze">

The issuer can freeze an account you hold without your involvement, so
detection has to come from monitoring the account rather than from a failed
withdrawal. Issuer side:

<CodeGroup>
```bash TypeScript
npx tsx freeze.ts $CUSTODIAN
```

```bash Rust
cargo run --release --bin freeze -- $CUSTODIAN
```
</CodeGroup>

Now read the account again:

```bash spl-token
spl-token display $CUSTODY_ATA --url ${RPC_URL:-devnet}
```

<div className="sol-run" data-run="paths/assets/gated-token/display-frozen" data-tab="spl-token">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account after the issuer freezes it</span></div>
<div className="sol-run-out">

```text Output

SPL Token Account
  Address: EqM2po44bk4JqjMeyynvaGd7aFWquBgLmnyVgMHyt1GC
  Program: TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
  Balance: 500
  Decimals: 6
  Mint: 8ComqBcog3Aig4hYN9PcCQHcK4rCCUhv7QoxUfrVVB66
  Owner: 6tUvc1Jco5iA8c1JKpjtLFwLvLSXTCfjtoYnnTazH7yH
  State: Frozen
  Delegation: (not set)
  Close authority: (not set)
Extensions:
  Immutable owner

* This token has a permanent delegate! 
  This means the mint may withdraw all funds from this account at any time.
  If this was not adequately disclosed to you, you may be dealing with a malicious mint.
```

</div>
</div>

From code, run `read-account` with `$CUSTODY_ATA` again:

<Tabs>
<Tab title="Kit">
<div className="sol-tab-label">Kit</div>

```ts
// npx tsx read-account.ts <token account> [commitment]
import { address, type Commitment } from "@solana/kit";
import { AccountState, fetchToken } from "@solana-program/token-2022";
import { arg, rpc } from "./common";

const tokenAccount = address(arg(1, "the token account"));
// Read at a stated commitment level. Use "finalized" for anything that feeds
// a book of record; "confirmed" is enough for a display.
const commitment = (process.argv[3] ?? "confirmed") as Commitment;

const { data } = await fetchToken(rpc, tokenAccount, { commitment });
console.log("Mint:", data.mint);
console.log("Owner:", data.owner);
console.log("Balance (base units):", data.amount.toString());
console.log("State:", AccountState[data.state]);
```

<div className="sol-run" data-run="paths/assets/gated-token/read-frozen" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account after the issuer freezes it</span></div>
<div className="sol-run-out">

```text Output
Mint: 8ComqBcog3Aig4hYN9PcCQHcK4rCCUhv7QoxUfrVVB66
Owner: 6tUvc1Jco5iA8c1JKpjtLFwLvLSXTCfjtoYnnTazH7yH
Balance (base units): 500000000
State: Frozen
```

</div>
</div>

</Tab>
<Tab title="Web3.js v3">
<div className="sol-tab-label">Web3.js v3</div>

```ts
// npx tsx read-account.ts <token account> [commitment]
import { type Commitment, PublicKey } from "@solana/web3.js";
import { AccountState, getTokenDecoder } from "@solana-program/token-2022";
import { arg, connection } from "./common";

const tokenAccount = new PublicKey(arg(1, "the token account"));
// Read at a stated commitment level. Use "finalized" for anything that feeds
// a book of record; "confirmed" is enough for a display.
const commitment = (process.argv[3] ?? "confirmed") as Commitment;

const info = await connection.getAccountInfo(tokenAccount, commitment);
const data = getTokenDecoder().decode(info!.data);
console.log("Mint:", data.mint);
console.log("Owner:", data.owner);
console.log("Balance (base units):", data.amount.toString());
console.log("State:", AccountState[data.state]);
```

<div className="sol-run" data-run="paths/assets/gated-token/read-frozen" data-tab="Web3.js v3">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account after the issuer freezes it</span></div>
<div className="sol-run-out">

```text Output
Mint: 8xDpQoKEXGrtCm5JwseD2v7KHCNnXv8kQmm61Cjozn7o
Owner: CYeEVDXLFbeMQH2Dhsiimpt5Q3Vw6Y4WDS4tpijN31q8
Balance (base units): 500000000
State: Frozen
```

</div>
</div>

</Tab>
<Tab title="Rust">
<div className="sol-tab-label">Rust</div>

```rust
// cargo run --release --bin read-account -- <token account> [commitment]
use anyhow::{anyhow, Result};
use gated_token::{arg, arg_pubkey, rpc_with};
use solana_commitment_config::CommitmentConfig;
use spl_token_2022_interface::{
    extension::StateWithExtensions,
    state::{Account, AccountState},
};

#[tokio::main]
async fn main() -> Result<()> {
    let token_account = arg_pubkey(1, "the token account")?;
    // Read at a stated commitment level. Use "finalized" for anything that
    // feeds a book of record; "confirmed" is enough for a display.
    let commitment = match arg(2, "the commitment").as_deref() {
        Ok("finalized") => CommitmentConfig::finalized(),
        _ => CommitmentConfig::confirmed(),
    };
    let rpc = rpc_with(commitment);
    let account = rpc
        .get_account_with_commitment(&token_account, commitment)
        .await?
        .value
        .ok_or_else(|| anyhow!("{token_account} not found at {commitment:?}"))?;
    let state = StateWithExtensions::<Account>::unpack(&account.data)?.base;

    println!("Mint: {}", state.mint);
    println!("Owner: {}", state.owner);
    println!("Balance (base units): {}", state.amount);
    let label = if state.state == AccountState::Frozen {
        "Frozen"
    } else {
        "Initialized"
    };
    println!("State: {label}");
    Ok(())
}
```

<div className="sol-run" data-run="paths/assets/gated-token/read-frozen" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account after the issuer freezes it</span></div>
<div className="sol-run-out">

```text Output
Mint: 3zsS4p5aDBiqLmCynUBayqCM9WWR35jr51tT4maAT1P1
Owner: BeoQ6d1SXZqxpfL3dTQKKk9Bw278Z5yQYsUe2dQcHieE
Balance (base units): 500000000
State: Frozen
```

</div>
</div>

</Tab>
</Tabs>

**State** is now `Frozen`. The balance is unchanged: the assets are still
there but cannot move. Report a frozen position as unavailable, not as zero.

Ask the issuer to restore it before you continue:

<CodeGroup>
```bash TypeScript
npx tsx thaw.ts $CUSTODIAN
```

```bash Rust
cargo run --release --bin thaw -- $CUSTODIAN
```
</CodeGroup>

</Step>

<Step title="Reconcile at a stated commitment level">

Reconciliation against a book of record needs a defined point in time, not
"now." `spl-token` has no `--commitment` flag: it reads at the commitment set
in the Solana CLI config, `confirmed` by default. For a `finalized` read, keep
a separate config file and pass it with `-C`.

The config file replaces your settings rather than adding to them, so it has
to name the cluster as well as the commitment. Without `json_rpc_url`, the read
goes to mainnet, where `$CUSTODY_ATA` does not exist. The command below
writes `$RPC_URL` into it when it is set, and devnet otherwise.

```bash spl-token
cat > ~/.config/solana/finalized.yml <<YAML
json_rpc_url: ${RPC_URL:-https://api.devnet.solana.com}
websocket_url: ""
keypair_path: ~/.config/solana/demo-custodian.json
commitment: finalized
YAML
```

Then read the account with that config:

```bash spl-token
spl-token display $CUSTODY_ATA -C ~/.config/solana/finalized.yml
```

<div className="sol-run" data-run="paths/assets/gated-token/display-finalized" data-tab="spl-token">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account at finalized commitment</span></div>
<div className="sol-run-out">

```text Output

SPL Token Account
  Address: EqM2po44bk4JqjMeyynvaGd7aFWquBgLmnyVgMHyt1GC
  Program: TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
  Balance: 500
  Decimals: 6
  Mint: 8ComqBcog3Aig4hYN9PcCQHcK4rCCUhv7QoxUfrVVB66
  Owner: 6tUvc1Jco5iA8c1JKpjtLFwLvLSXTCfjtoYnnTazH7yH
  State: Initialized
  Delegation: (not set)
  Close authority: (not set)
Extensions:
  Immutable owner

* This token has a permanent delegate! 
  This means the mint may withdraw all funds from this account at any time.
  If this was not adequately disclosed to you, you may be dealing with a malicious mint.
```

</div>
</div>

The scripts take the commitment level as their second argument, so from code
run `read-account` with `$CUSTODY_ATA finalized`:

<Tabs>
<Tab title="Kit">
<div className="sol-tab-label">Kit</div>

```ts
// npx tsx read-account.ts <token account> [commitment]
import { address, type Commitment } from "@solana/kit";
import { AccountState, fetchToken } from "@solana-program/token-2022";
import { arg, rpc } from "./common";

const tokenAccount = address(arg(1, "the token account"));
// Read at a stated commitment level. Use "finalized" for anything that feeds
// a book of record; "confirmed" is enough for a display.
const commitment = (process.argv[3] ?? "confirmed") as Commitment;

const { data } = await fetchToken(rpc, tokenAccount, { commitment });
console.log("Mint:", data.mint);
console.log("Owner:", data.owner);
console.log("Balance (base units):", data.amount.toString());
console.log("State:", AccountState[data.state]);
```

<div className="sol-run" data-run="paths/assets/gated-token/read-finalized" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account at finalized commitment</span></div>
<div className="sol-run-out">

```text Output
Mint: 8ComqBcog3Aig4hYN9PcCQHcK4rCCUhv7QoxUfrVVB66
Owner: 6tUvc1Jco5iA8c1JKpjtLFwLvLSXTCfjtoYnnTazH7yH
Balance (base units): 500000000
State: Initialized
```

</div>
</div>

</Tab>
<Tab title="Web3.js v3">
<div className="sol-tab-label">Web3.js v3</div>

```ts
// npx tsx read-account.ts <token account> [commitment]
import { type Commitment, PublicKey } from "@solana/web3.js";
import { AccountState, getTokenDecoder } from "@solana-program/token-2022";
import { arg, connection } from "./common";

const tokenAccount = new PublicKey(arg(1, "the token account"));
// Read at a stated commitment level. Use "finalized" for anything that feeds
// a book of record; "confirmed" is enough for a display.
const commitment = (process.argv[3] ?? "confirmed") as Commitment;

const info = await connection.getAccountInfo(tokenAccount, commitment);
const data = getTokenDecoder().decode(info!.data);
console.log("Mint:", data.mint);
console.log("Owner:", data.owner);
console.log("Balance (base units):", data.amount.toString());
console.log("State:", AccountState[data.state]);
```

<div className="sol-run" data-run="paths/assets/gated-token/read-finalized" data-tab="Web3.js v3">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account at finalized commitment</span></div>
<div className="sol-run-out">

```text Output
Mint: 8xDpQoKEXGrtCm5JwseD2v7KHCNnXv8kQmm61Cjozn7o
Owner: CYeEVDXLFbeMQH2Dhsiimpt5Q3Vw6Y4WDS4tpijN31q8
Balance (base units): 500000000
State: Initialized
```

</div>
</div>

</Tab>
<Tab title="Rust">
<div className="sol-tab-label">Rust</div>

```rust
// cargo run --release --bin read-account -- <token account> [commitment]
use anyhow::{anyhow, Result};
use gated_token::{arg, arg_pubkey, rpc_with};
use solana_commitment_config::CommitmentConfig;
use spl_token_2022_interface::{
    extension::StateWithExtensions,
    state::{Account, AccountState},
};

#[tokio::main]
async fn main() -> Result<()> {
    let token_account = arg_pubkey(1, "the token account")?;
    // Read at a stated commitment level. Use "finalized" for anything that
    // feeds a book of record; "confirmed" is enough for a display.
    let commitment = match arg(2, "the commitment").as_deref() {
        Ok("finalized") => CommitmentConfig::finalized(),
        _ => CommitmentConfig::confirmed(),
    };
    let rpc = rpc_with(commitment);
    let account = rpc
        .get_account_with_commitment(&token_account, commitment)
        .await?
        .value
        .ok_or_else(|| anyhow!("{token_account} not found at {commitment:?}"))?;
    let state = StateWithExtensions::<Account>::unpack(&account.data)?.base;

    println!("Mint: {}", state.mint);
    println!("Owner: {}", state.owner);
    println!("Balance (base units): {}", state.amount);
    let label = if state.state == AccountState::Frozen {
        "Frozen"
    } else {
        "Initialized"
    };
    println!("State: {label}");
    Ok(())
}
```

<div className="sol-run" data-run="paths/assets/gated-token/read-finalized" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the custody account at finalized commitment</span></div>
<div className="sol-run-out">

```text Output
Mint: 3zsS4p5aDBiqLmCynUBayqCM9WWR35jr51tT4maAT1P1
Owner: BeoQ6d1SXZqxpfL3dTQKKk9Bw278Z5yQYsUe2dQcHieE
Balance (base units): 500000000
State: Initialized
```

</div>
</div>

</Tab>
</Tabs>

Use a separate config file, not `solana config set --commitment finalized`,
for a reconciliation job, so other commands keep their own commitment.

`solana account` returns the raw account: its lamports, owner program, and
data bytes, base64-encoded, with the balance inside the data:

```bash solana
solana account $CUSTODY_ATA --url ${RPC_URL:-devnet} \
  --commitment finalized --output json
```

For a list of positions across a client's holdings:

```bash spl-token
spl-token accounts --owner $CUSTODIAN --url ${RPC_URL:-devnet}
```

Use `finalized` for anything that feeds a book of record; see
[settlement and finality](/developers/docs/defi/finality) for why the other
levels are not appropriate there.

</Step>

</Steps>

## Production integration requirements

Everything above is a read or a single transaction. A production integration
also needs continuous detection: subscribe to the accounts you hold and to the
mint, where a pause is recorded, so a freeze, a pause, or a permanent-delegate
transfer raises an alert before a client instruction fails on it.
[Custody integration](/developers/docs/tokenization/custody/custody-integration)
lists what a custodian's systems have to support.

## Next steps

- [Prepare a vault for a gated token](/developers/docs/tokenization/tutorials/vault):
  the asset manager's side of the same token
- [Custody integration](/developers/docs/tokenization/custody/custody-integration):
  what a custodian has to support to hold a gated asset
