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

# Gate the holders

> Put an address on an onchain allowlist so its token account can be thawed through the gate, and confirm that an address which is not on the list cannot hold the token.

Your mint creates every token account frozen. This step uses the gate: an
address you approve can have its account thawed against an onchain list, and an
address you have not approved cannot.

## How the pieces fit

Three programs cooperate:

1. **Token-2022** holds the mint and creates every new account frozen.
2. **The Token ACL program** holds the delegated freeze authority, through a
   config account for each mint, and exposes a permissionless thaw. It does not
   decide who qualifies.
3. **A gate program** makes that decision. With an address-based list as the
   gate, qualifying means being on the list.

Three overrides remain with the issuer: freeze or thaw an account directly,
swap the gate program, or reclaim the freeze authority from Token ACL.

```mermaid
flowchart TD
  accTitle: How Token ACL thaws a holder's account
  accDescr: A new holder account opens frozen. Anyone can send a permissionless thaw to the Token ACL program, which asks the gate program; the Token ACL config authority can also freeze or thaw directly, swap the gate, or reclaim the freeze authority. The gate reads the list and approves the thaw only if the wallet qualifies; otherwise the account stays frozen and the transaction fails. In allowlist mode only listed wallets qualify; in blocklist mode every wallet qualifies except listed ones. An issuer can also write a custom gate. The list operator maintains the list, driven by offchain checks such as KYC and sanctions screening, and by attestations.
  H["New holder account<br/>Opens frozen"] -->|permissionless thaw| ACL["Token ACL program<br/>Holds the freeze authority<br/>Does not decide who qualifies"]
  CA["Token ACL config authority<br/>Fee payer in this tutorial<br/>Can freeze or thaw directly, swap the gate, or reclaim the freeze authority"] -.-> ACL
  ACL -->|asks| G["Gate program<br/>Does the wallet qualify?"]
  ACL -.->|or asks| CG["Custom gate<br/>Issuer-written logic, for example<br/>onchain identity checks"]
  G -.-> L["List, one entry per wallet<br/>Allowlist mode: listed wallets qualify<br/>Blocklist mode: unlisted wallets qualify"]
  K["Offchain checks<br/>KYC and sanctions screening<br/>Attestations"] --> LO["List operator<br/>Issuer, transfer agent, or provider"]
  LO -->|adds and removes wallets| L
  G -->|yes| OK["Account thawed<br/>Later transfers are ordinary transfers"]
  G -->|no| NO["Account stays frozen<br/>The transaction fails"]
  class G focal
```

<div className="sol-mermaid" data-fallback="mermaid" data-mermaid="2b7f15c6b6bf">
  <img className="block dark:hidden" src="/docs-assets/assets/docs/mermaid/2b7f15c6b6bf-light.svg" alt="How Token ACL thaws a holder's account. A new holder account opens frozen. Anyone can send a permissionless thaw to the Token ACL program, which asks the gate program; the Token ACL config authority can also freeze or thaw directly, swap the gate, or reclaim the freeze authority. The gate reads the list and approves the thaw only if the wallet qualifies; otherwise the account stays frozen and the transaction fails. In allowlist mode only listed wallets qualify; in blocklist mode every wallet qualifies except listed ones. An issuer can also write a custom gate. The list operator maintains the list, driven by offchain checks such as KYC and sanctions screening, and by attestations." />

  <img className="hidden dark:block" src="/docs-assets/assets/docs/mermaid/2b7f15c6b6bf.svg" alt="How Token ACL thaws a holder's account. A new holder account opens frozen. Anyone can send a permissionless thaw to the Token ACL program, which asks the gate program; the Token ACL config authority can also freeze or thaw directly, swap the gate, or reclaim the freeze authority. The gate reads the list and approves the thaw only if the wallet qualifies; otherwise the account stays frozen and the transaction fails. In allowlist mode only listed wallets qualify; in blocklist mode every wallet qualifies except listed ones. An issuer can also write a custom gate. The list operator maintains the list, driven by offchain checks such as KYC and sanctions screening, and by attestations." />

  <img className="block dark:hidden" src="/docs-assets/assets/docs/mermaid/2b7f15c6b6bf-sm-light.svg" alt="How Token ACL thaws a holder's account. A new holder account opens frozen. Anyone can send a permissionless thaw to the Token ACL program, which asks the gate program; the Token ACL config authority can also freeze or thaw directly, swap the gate, or reclaim the freeze authority. The gate reads the list and approves the thaw only if the wallet qualifies; otherwise the account stays frozen and the transaction fails. In allowlist mode only listed wallets qualify; in blocklist mode every wallet qualifies except listed ones. An issuer can also write a custom gate. The list operator maintains the list, driven by offchain checks such as KYC and sanctions screening, and by attestations." />

  <img className="hidden dark:block" src="/docs-assets/assets/docs/mermaid/2b7f15c6b6bf-sm.svg" alt="How Token ACL thaws a holder's account. A new holder account opens frozen. Anyone can send a permissionless thaw to the Token ACL program, which asks the gate program; the Token ACL config authority can also freeze or thaw directly, swap the gate, or reclaim the freeze authority. The gate reads the list and approves the thaw only if the wallet qualifies; otherwise the account stays frozen and the transaction fails. In allowlist mode only listed wallets qualify; in blocklist mode every wallet qualifies except listed ones. An issuer can also write a custom gate. The list operator maintains the list, driven by offchain checks such as KYC and sanctions screening, and by attestations." />
</div>

<Steps titleSize="h3">

<Step title="Confirm the gate is in place">

The create transaction in the previous step already handed the freeze
authority to the Token ACL mint config, created the allowlist, pointed the gate
at it, and turned on permissionless thaw. The
[inspect-mint output](/developers/docs/tokenization/tutorials/issuing/create-the-mint#confirm-what-you-built)
confirms it: the freeze authority is `$MINT_CONFIG`, a program-derived address
of the Token ACL program (`TACLkU6CiCdkQN2MjoyDkVg2yAH9zkxiHDsiztQ52TP`), not
the program ID itself.

If the freeze authority is anything else, the mint was created without Token
ACL, and nothing can thaw an account through the gate. Whether that can be
fixed depends on what the freeze authority is.

<Accordion title="Wiring the gate on a mint created without it">

Start from the freeze authority in the `inspect-mint` output:

- **Your own key**: recoverable. Token ACL's create config instruction, signed
  by that key, takes the freeze authority over. Run the script below.
- **None**: a freeze authority cannot be restored once it is unset. Nothing can
  thaw an account, so the mint cannot be gated. Create a new one.
- **Any other address**: whoever holds that key has to sign the create config
  instruction. If nobody can sign for it, create a new mint.

The script does what `enableSrfc37: true` does at creation, in one transaction
signed by the fee payer as the current freeze authority. It is written for the
Mosaic SDK project from
[before you start](/developers/docs/tokenization/tutorials/issuing#before-you-start).
Save it as `wire-gate.ts` and run it with `$MINT` exported:

```ts title="Mosaic SDK"
// npx tsx wire-gate.ts
import {
  address,
  appendTransactionMessageInstructions,
  createTransactionMessage,
  pipe,
  setTransactionMessageFeePayerSigner,
  setTransactionMessageLifetimeUsingBlockhash,
} from "@solana/kit";
import {
  getCreateConfigInstructions,
  getCreateListInstructions,
  getEnablePermissionlessThawInstructions,
  getSetExtraMetasInstructions,
} from "@solana/mosaic-sdk";
import { env, loadSigner, rpc, sendMessage } from "./common";

// The mint's current freeze authority: the fee payer in this tutorial.
const payer = await loadSigner("tokenization-demo");
const mint = address(env("MINT"));
const gatingProgram = address("GATEzzqxhJnsWF6vHRsgtixxSB8PaQdcqGEVTEHWiULz");

// What enableSrfc37 does at creation, in one transaction: create the Token
// ACL config (which takes over the freeze authority), create the allowlist,
// register it with the gate, and turn on permissionless thaw.
const config = await getCreateConfigInstructions({
  authority: payer,
  mint,
  gatingProgram,
});
const list = await getCreateListInstructions({ authority: payer, mint });
const instructions = [
  ...config.instructions,
  ...list.instructions,
  ...(await getSetExtraMetasInstructions({
    authority: payer,
    mint,
    addresses: [list.listConfig],
  })),
  ...(await getEnablePermissionlessThawInstructions({ authority: payer, mint })),
];

const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
await sendMessage(
  pipe(
    createTransactionMessage({ version: 0 }),
    (m) => setTransactionMessageFeePayerSigner(payer, m),
    (m) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, m),
    (m) => appendTransactionMessageInstructions(instructions, m),
  ),
);
if (process.exitCode) process.exit();
console.log("Allowlist:", list.listConfig);
console.log("Freeze authority (Token ACL mint config):", config.mintConfig);
```

<div className="sol-run" data-run="paths/assets/gated-token/wire-gate" data-tab="Mosaic SDK">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Wiring the gate on a mint created without it</span></div>
<div className="sol-run-out">

```text Output
Signature: 4rZf7J4d37jCWZddZZdJkwEvd3sFAykRFnWaySTfL26VtjS97UZJzxhQqNrjj8xy9scQyspGepuJ6cNxuxQ2Eqh4
Allowlist: 6HsWTUHUd5ZHDejqUCGRSVAuh9esjJkoJ8f6ksicuzu3
Freeze authority (Token ACL mint config): 95dkYanMbfpvphYB3E39H8bGuyWuBNo1KyuJKo2gXthL
```

</div>
</div>

Export the two addresses it prints, then run `inspect-mint` again to confirm
the freeze authority is now the Token ACL mint config:

```bash Terminal
export LIST=<the allowlist>
export MINT_CONFIG=<the freeze authority>
```

<Warning>
Do not move the freeze authority by hand first, for example with
`spl-token authorize $MINT freeze <address>`. Token ACL's create config
instruction must be signed by the current freeze authority, and it moves the
authority itself. A freeze authority set by hand to the Token ACL program or to
the mint config address cannot sign: create config then fails with custom
program error `0x0` (`InvalidAuthority`), nothing can move the freeze authority
again, and the mint cannot be gated.
</Warning>

</Accordion>

</Step>

<Step title="Create a holder to approve">

Generate a key for an onboarded client, and fund it from the fee payer so it
can pay its own transaction fees. `${RPC_URL:-devnet}` points the Solana CLI at
the same network as the scripts.

```bash Terminal
solana-keygen new --no-bip39-passphrase --silent \
  --outfile ~/.config/solana/demo-holder.json
export HOLDER=$(solana-keygen pubkey ~/.config/solana/demo-holder.json)
solana transfer $HOLDER 0.1 --allow-unfunded-recipient \
  --keypair ~/.config/solana/tokenization-demo.json --url ${RPC_URL:-devnet}
```

</Step>

<Step title="Add the holder to the allowlist">

This records the onboarding decision. Save this as `allowlist-add.ts` (in
Rust, `src/bin/allowlist-add.rs`) and run it with `$HOLDER`.

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

```ts
// npx tsx allowlist-add.ts <wallet>
import { address } from "@solana/kit";
import { createAddToAllowlistTransaction } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";

// The list authority is the key that created the mint.
const payer = await loadSigner("tokenization-demo");
const mint = address(env("MINT"));
const wallet = address(arg(1, "the wallet to allowlist"));

// Adds the wallet to the allowlist behind the Token ACL gate. If the wallet
// already has a frozen token account, the SDK thaws it in the same
// transaction.
await sendMessage(
  await createAddToAllowlistTransaction(rpc, mint, wallet, payer),
);
```

<div className="sol-run" data-run="paths/assets/gated-token/allowlist-add" data-tab="Mosaic SDK">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Adding the holder to the allowlist</span></div>
<div className="sol-run-out">

```text Output
Signature: 5q17FzRs2r287U5VP1sanZ8Py22Gmk81SCe91131afg8CtvjmwZAWozijRYCwqDczMC4GRBECts45XgiuNQqTo4j
```

</div>
</div>

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

```ts
// npx tsx allowlist-add.ts <wallet>
import { address } from "@solana/kit";
import {
  findListConfigPda,
  findWalletEntryPda,
  getAddWalletInstruction,
} from "@solana/token-acl-gate-sdk";
import { arg, env, loadSigner, send } from "./common";

// The list authority is the key that created the mint.
const payer = await loadSigner("tokenization-demo");
const mint = address(env("MINT"));
const wallet = address(arg(1, "the wallet to allowlist"));

// The allowlist is a gate-program account keyed by its authority and the
// mint. Each approved wallet gets its own entry account under that list.
const [listConfig] = await findListConfigPda({
  authority: payer.address,
  seed: mint,
});
const [walletEntry] = await findWalletEntryPda({ listConfig, wallet });

// This adds the entry only. A wallet that already holds a frozen account on
// this mint thaws it through the gate afterwards (see gate.ts).
await send(payer, [
  getAddWalletInstruction({
    authority: payer,
    payer,
    listConfig,
    wallet,
    walletEntry,
  }),
]);
```

<div className="sol-run" data-run="paths/assets/gated-token/allowlist-add" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Adding the holder to the allowlist</span></div>
<div className="sol-run-out">

```text Output
Signature: 3oSLcEXD9UMQ1tGaeRgmL4YVFHCZnMBtz4NeNiQjB3tzTUTAAPLAvkkb1su5mVnDyd4XLN5Uw4aM7q2TAiHUaWLL
```

</div>
</div>

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

```ts
// npx tsx allowlist-add.ts <wallet>
import {
  findListConfigPda,
  findWalletEntryPda,
  getAddWalletInstruction,
} from "@solana/token-acl-gate-sdk";
import { addressOf, arg, env, loadKeypair, send } from "./common";

// The list authority is the key that created the mint.
const payer = await loadKeypair("tokenization-demo");
const mint = addressOf(env("MINT"));
const wallet = addressOf(arg(1, "the wallet to allowlist"));

// The allowlist is a gate-program account keyed by its authority and the
// mint. Each approved wallet gets its own entry account under that list.
const [listConfig] = await findListConfigPda({
  authority: payer.publicKey.toBase58(),
  seed: mint,
});
const [walletEntry] = await findWalletEntryPda({ listConfig, wallet });

// This adds the entry only. A wallet that already holds a frozen account on
// this mint thaws it through the gate afterwards (see gate.ts).
await send(
  [payer],
  [
    getAddWalletInstruction({
      authority: payer,
      payer,
      listConfig,
      wallet,
      walletEntry,
    }),
  ],
);
```

<div className="sol-run" data-run="paths/assets/gated-token/allowlist-add" data-tab="Web3.js v3">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Adding the holder to the allowlist</span></div>
<div className="sol-run-out">

```text Output
Signature: 5oxM4bLN7x4GyrHSFxnuzGUtBCM62DHQffi5jFhbpU3TxBBGtRqehyLyp3dwk5zqUDDmy7Lsc4ZYrePNj5oCdu8R
```

</div>
</div>

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

```rust
// cargo run --release --bin allowlist-add -- <wallet>
use anyhow::Result;
use gated_token::{acl, arg_pubkey, env, load_keypair, rpc, send};
use solana_sdk::signature::Signer;

#[tokio::main]
async fn main() -> Result<()> {
    let rpc = rpc();
    // The list authority is the key that created the mint.
    let payer = load_keypair("tokenization-demo")?;
    let mint = env("MINT")?;
    let wallet = arg_pubkey(1, "the wallet to allowlist")?;

    // This adds the entry only. A wallet that already holds a frozen account
    // on this mint thaws it through the gate afterwards (see src/acl.rs).
    let list = acl::list_config(&payer.pubkey(), &mint);
    send(
        &rpc,
        &[&payer],
        &[acl::add_wallet(&payer.pubkey(), &list, &wallet)],
    )
    .await
}
```

<div className="sol-run" data-run="paths/assets/gated-token/allowlist-add" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Adding the holder to the allowlist</span></div>
<div className="sol-run-out">

```text Output
Signature: 2GRZurwvozrTVS4TKag1sbqH6e7J3NzjqB9ntUveGpNoeyM2FdzyrrRYAvvKUXSHDMuB9vTCt5xEWTb1L6ktDafT
```

</div>
</div>

</Tab>
</Tabs>

Read the list back to confirm. The script takes the list from `$LIST`, the
allowlist address `create-the-mint` printed.

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

```ts
// npx tsx fetch-list.ts
import { address } from "@solana/kit";
import { getList } from "@solana/mosaic-sdk";
import { env, rpc } from "./common";

// $LIST is the allowlist address create-the-mint.ts printed.
const list = await getList({ rpc, listConfig: address(env("LIST")) });
console.log("List:", list.listConfig);
// Mode 0 is an allowlist, 2 a blocklist.
console.log("Mode:", list.mode === 0 ? "Allow" : "Block");
console.log("Authority:", list.authority);
console.log("Wallets:", list.wallets.length ? list.wallets : "none");
```

<div className="sol-run" data-run="paths/assets/gated-token/fetch-list" data-tab="Mosaic SDK">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the allowlist after adding the holder</span></div>
<div className="sol-run-out">

```text Output
List: 7VZfn6MWo2KxHySn7c3zvMSdm6DGbAfUh3HCcpTCAxsh
Mode: Allow
Authority: Grr9mjov4Ao553eJfERUuGK7GPv2BmJsnsS7xxdcWjXF
Wallets: [ '8hkXZxsJLcRqVEy4mk9zT9y5edHBR58Z2jw1dQFPnYN9' ]
```

</div>
</div>

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

```ts
// npx tsx fetch-list.ts
import {
  address,
  type Base58EncodedBytes,
  getBase64Encoder,
} from "@solana/kit";
import {
  fetchListConfig,
  getWalletEntryDecoder,
  getWalletEntrySize,
  Mode,
  TOKEN_ACL_GATE_PROGRAM_PROGRAM_ADDRESS,
} from "@solana/token-acl-gate-sdk";
import { env, rpc } from "./common";

// $LIST is the allowlist address create-the-mint.ts printed.
const listConfig = address(env("LIST"));
const { data: list } = await fetchListConfig(rpc, listConfig);
console.log("List:", listConfig);
console.log("Mode:", Mode[list.mode]);
console.log("Authority:", list.authority);

// Every approved wallet is its own entry account that points back at the
// list, so membership is read with a program-accounts query on that pointer.
const entries = await rpc
  .getProgramAccounts(TOKEN_ACL_GATE_PROGRAM_PROGRAM_ADDRESS, {
    encoding: "base64",
    filters: [
      { dataSize: BigInt(getWalletEntrySize()) },
      {
        memcmp: {
          offset: 33n,
          bytes: listConfig as string as Base58EncodedBytes,
          encoding: "base58",
        },
      },
    ],
  })
  .send();
const wallets = entries.map(
  ({ account }) =>
    getWalletEntryDecoder().decode(getBase64Encoder().encode(account.data[0]))
      .walletAddress,
);
console.log("Wallets:", wallets.length ? wallets : "none");
```

<div className="sol-run" data-run="paths/assets/gated-token/fetch-list" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the allowlist after adding the holder</span></div>
<div className="sol-run-out">

```text Output
List: 4jLUb27keHXA2T99sudNRN4ohynsPw4zjaAowhFDpkmN
Mode: Allow
Authority: BK9pK1NZKR3jfmhCmU6tKPj14ZtCcvPW8KgfzKaB7Q2U
Wallets: [ 'HPC5U5gHdQPdrKsojX7nG44R1MbEgjgmqtc3MypsmSq9' ]
```

</div>
</div>

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

```ts
// npx tsx fetch-list.ts
import { PublicKey } from "@solana/web3.js";
import {
  getListConfigDecoder,
  getWalletEntryDecoder,
  getWalletEntrySize,
  Mode,
  TOKEN_ACL_GATE_PROGRAM_PROGRAM_ADDRESS,
} from "@solana/token-acl-gate-sdk";
import { connection, env } from "./common";

// $LIST is the allowlist address create-the-mint.ts printed.
const listConfig = new PublicKey(env("LIST"));
const listAccount = await connection.getAccountInfo(listConfig);
const list = getListConfigDecoder().decode(listAccount!.data);
console.log("List:", listConfig.toBase58());
console.log("Mode:", Mode[list.mode]);
console.log("Authority:", list.authority);

// Every approved wallet is its own entry account that points back at the
// list, so membership is read with a program-accounts query on that pointer.
const entries = await connection.getProgramAccounts(
  new PublicKey(TOKEN_ACL_GATE_PROGRAM_PROGRAM_ADDRESS),
  {
    filters: [
      { dataSize: getWalletEntrySize() },
      { memcmp: { offset: 33, bytes: listConfig.toBase58() } },
    ],
  },
);
const wallets = entries.map(
  ({ account }) => getWalletEntryDecoder().decode(account.data).walletAddress,
);
console.log("Wallets:", wallets.length ? wallets : "none");
```

<div className="sol-run" data-run="paths/assets/gated-token/fetch-list" 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 allowlist after adding the holder</span></div>
<div className="sol-run-out">

```text Output
List: DPVXMbK2kckwTeGXDntCyDNpnKHzaSboEMJeeYq5nTvJ
Mode: Allow
Authority: xZfpSyksW1VT3CSKDCfY7imda2aeHcxfudasCVctk6s
Wallets: [ '4Rse9xYsYBBMaVtgKN8gfKR4huFScheX1XE5YxRkNMk2' ]
```

</div>
</div>

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

```rust
// cargo run --release --bin fetch-list
use anyhow::{anyhow, Result};
use gated_token::{acl, env, rpc};
use solana_account_decoder_client_types::UiAccountEncoding;
use solana_client::{
    rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig},
    rpc_filter::{Memcmp, RpcFilterType},
};
use solana_sdk::pubkey::Pubkey;

#[tokio::main]
async fn main() -> Result<()> {
    let rpc = rpc();
    // $LIST is the allowlist address create-the-mint printed. Layout:
    // discriminator (1), authority (32), seed (32), mode (1).
    let list = env("LIST")?;
    let data = rpc.get_account_data(&list).await?;
    let modes = ["Allow", "Unused", "Block"];
    println!("List: {list}");
    println!("Mode: {}", modes[data[65] as usize]);
    println!("Authority: {}", Pubkey::try_from(&data[1..33])?);

    // Every approved wallet is its own 65-byte entry account: discriminator
    // (1), wallet (32), list (32). Membership is read by filtering on the list.
    let entries = rpc
        .get_program_ui_accounts_with_config(
            &acl::GATE,
            RpcProgramAccountsConfig {
                filters: Some(vec![
                    RpcFilterType::DataSize(65),
                    RpcFilterType::Memcmp(Memcmp::new_raw_bytes(33, list.to_bytes().to_vec())),
                ]),
                account_config: RpcAccountInfoConfig {
                    encoding: Some(UiAccountEncoding::Base64),
                    ..Default::default()
                },
                ..Default::default()
            },
        )
        .await?;
    let mut wallets = Vec::new();
    for (_, account) in &entries {
        let data = account.data.decode().ok_or_else(|| anyhow!("bad entry"))?;
        wallets.push(Pubkey::try_from(&data[1..33])?.to_string());
    }
    println!("Wallets: {wallets:?}");
    Ok(())
}
```

<div className="sol-run" data-run="paths/assets/gated-token/fetch-list" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Reading the allowlist after adding the holder</span></div>
<div className="sol-run-out">

```text Output
List: Bos4ACRw2FtEH2jfCRuJjkgkNdV8KJynbur3gmMJ3kDT
Mode: Allow
Authority: G5YVqc5e5wG4WBCcJwK1BhHE8hLWX5W4bu3uksoENBG8
Wallets: ["5HXUujBbZqSYMpAhe4ywyrJhWpEE2m5cWef3eQssDDXz"]
```

</div>
</div>

</Tab>
</Tabs>

</Step>

<Step title="Mint to the holder">

Minting creates the holder's token account and thaws it in the same
transaction: the script inserts Token ACL's permissionless thaw between the
account creation and the mint, and the gate program approves it because the
holder is on the list. If the holder is not on the list, the whole transaction
fails, so there is no partly minted state. Save this as `mint.ts` (in Rust,
`src/bin/mint.rs`) and run it with `$HOLDER 1000`.

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

```ts
// npx tsx mint.ts <recipient> <amount>
import { address } from "@solana/kit";
import { createMintToTransaction } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";

// The fee payer holds the mint authority on this mint.
const payer = await loadSigner("tokenization-demo");
const mint = address(env("MINT"));
const recipient = address(arg(1, "the recipient wallet"));
const amount = Number(arg(2, "the amount"));

// Creates the recipient's token account, thaws it through the Token ACL gate
// and mints, all in one transaction.
await sendMessage(
  await createMintToTransaction(rpc, mint, recipient, amount, payer, payer),
);
```

<div className="sol-run" data-run="paths/assets/gated-token/mint" data-tab="Mosaic SDK">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Minting 1000 to the holder</span></div>
<div className="sol-run-out">

```text Output
{
  discriminator: 1,
  bump: 255,
  enablePermissionlessThaw: true,
  enablePermissionlessFreeze: false,
  mint: '653XZoSFLEb7BuezYeLTiq5KBsdFDHZ71MfsybEzHr9G',
  freezeAuthority: 'Grr9mjov4Ao553eJfERUuGK7GPv2BmJsnsS7xxdcWjXF',
  gatingProgram: 'GATEzzqxhJnsWF6vHRsgtixxSB8PaQdcqGEVTEHWiULz'
}
EAEXfee6dPx7myBsnb6e4CEVgt9APZWdvYwYi54e7t4E
Signature: 54mBzSzFPmFK6RfzVkUaEQrDGD2xzRQLRFa3Jijq5n6VRi4yn58KqiYKLRN1VFtW1gUasQBymZ8nM94RcmmV84k8
```

</div>
</div>

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

```ts
// npx tsx mint.ts <recipient> <amount>
import { address } from "@solana/kit";
import { fetchMint, getMintToInstruction } from "@solana-program/token-2022";
import { arg, env, loadSigner, rpc, send, toBaseUnits } from "./common";
import { openThroughGate } from "./gate";

// The fee payer holds the mint authority on this mint.
const payer = await loadSigner("tokenization-demo");
const mint = address(env("MINT"));
const list = address(env("LIST"));
const recipient = address(arg(1, "the recipient wallet"));
const { data } = await fetchMint(rpc, mint);

// Create the account, thaw it through the gate, then mint: one transaction.
const { tokenAccount, instructions } = await openThroughGate(
  payer,
  mint,
  recipient,
  list,
);
await send(payer, [
  ...instructions,
  getMintToInstruction({
    mint,
    token: tokenAccount,
    mintAuthority: payer,
    amount: toBaseUnits(arg(2, "the amount"), data.decimals),
  }),
]);
```

<div className="sol-run" data-run="paths/assets/gated-token/mint" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Minting 1000 to the holder</span></div>
<div className="sol-run-out">

```text Output
Signature: 2cGz8eKKuqSDySH23YsudRmMZQDEtmRh7VjfpcTPWrHWhLDpPYHeXcQ95yPZ8emNwe5dzDAT4wUc8DSzNh4vynZ2
```

</div>
</div>

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

```ts
// npx tsx mint.ts <recipient> <amount>
import { PublicKey } from "@solana/web3.js";
import {
  getMintDecoder,
  getMintToInstruction,
} from "@solana-program/token-2022";
import {
  addressOf,
  arg,
  connection,
  env,
  loadKeypair,
  send,
  toBaseUnits,
} from "./common";
import { openThroughGate } from "./gate";

// The fee payer holds the mint authority on this mint.
const payer = await loadKeypair("tokenization-demo");
const mint = addressOf(env("MINT"));
const list = addressOf(env("LIST"));
const recipient = addressOf(arg(1, "the recipient wallet"));
const mintAccount = await connection.getAccountInfo(new PublicKey(mint));
const { decimals } = getMintDecoder().decode(mintAccount!.data);

// Create the account, thaw it through the gate, then mint: one transaction.
const { tokenAccount, instructions } = await openThroughGate(
  payer,
  mint,
  recipient,
  list,
);
await send(
  [payer],
  [
    ...instructions,
    getMintToInstruction({
      mint,
      token: tokenAccount,
      mintAuthority: payer,
      amount: toBaseUnits(arg(2, "the amount"), decimals),
    }),
  ],
);
```

<div className="sol-run" data-run="paths/assets/gated-token/mint" data-tab="Web3.js v3">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Minting 1000 to the holder</span></div>
<div className="sol-run-out">

```text Output
Signature: 5Y4RtJXos4G5yhnPMhJ7XHLjsK4csJSknTMmMwuH9MEUPACo2172sKHeCbduSmRuYoBLtThQptS6uYjRQ2BWnmTR
```

</div>
</div>

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

```rust
// cargo run --release --bin mint -- <recipient> <amount>
use anyhow::Result;
use gated_token::{
    acl, arg, arg_pubkey, env, load_keypair, mint_decimals, rpc, send, to_base_units, TOKEN_2022,
};
use solana_sdk::signature::Signer;
use spl_token_2022_interface::instruction::mint_to;

#[tokio::main]
async fn main() -> Result<()> {
    let rpc = rpc();
    // The fee payer holds the mint authority on this mint.
    let payer = load_keypair("tokenization-demo")?;
    let mint = env("MINT")?;
    let list = env("LIST")?;
    let recipient = arg_pubkey(1, "the recipient wallet")?;
    let decimals = mint_decimals(&rpc, &mint).await?;

    // Create the account, thaw it through the gate, then mint: one transaction.
    let (token_account, mut instructions) =
        acl::open_through_gate(&rpc, &payer.pubkey(), &mint, &recipient, &list).await?;
    instructions.push(mint_to(
        &TOKEN_2022,
        &mint,
        &token_account,
        &payer.pubkey(),
        &[],
        to_base_units(&arg(2, "the amount")?, decimals)?,
    )?);
    send(&rpc, &[&payer], &instructions).await
}
```

<div className="sol-run" data-run="paths/assets/gated-token/mint" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Minting 1000 to the holder</span></div>
<div className="sol-run-out">

```text Output
Signature: 5878Q2pLV8jgCuEDtvagyuqS4sKTvYP9nSGedgPTfeMUSzdKwJNBdPUmdg7sVbGDAyygdHs9EGUVMMEdE1rdqdK5
```

</div>
</div>

</Tab>
</Tabs>

The fee payer signs, because it holds the mint authority on this mint. Where
the mint authority sits on its own key, this is the script that uses it, and no
other key can create supply.

The Mosaic SDK output starts with a decoded Token ACL mint config and an
address. `@solana/token-acl-sdk` 0.4.0 prints them while it builds the
permissionless thaw; they are not part of the transaction.

</Step>

<Step title="Show that the gate rejects a non-holder">

Generate a third key, leave it off the list, and have the holder send tokens to
it. Save this as `transfer.ts` (in Rust, `src/bin/transfer.rs`) and run it with
`$OUTSIDER 1`.

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

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

```ts
// npx tsx transfer.ts <recipient> <amount>
import { address } from "@solana/kit";
import { createTransferTransaction } from "@solana/mosaic-sdk";
import { arg, env, loadSigner, rpc, sendMessage } from "./common";

// The holder signs and pays for its own transfer.
const holder = await loadSigner("demo-holder");
const mint = address(env("MINT"));

// Creates the recipient's token account if it is missing and thaws it
// through the gate before the transfer, so the gate decides whether the
// recipient may hold the token.
await sendMessage(
  await createTransferTransaction({
    rpc,
    mint,
    from: holder.address,
    to: address(arg(1, "the recipient wallet")),
    feePayer: holder,
    authority: holder,
    amount: arg(2, "the amount"),
  }),
);
```

<div className="sol-run" data-run="paths/assets/gated-token/transfer-blocked" data-tab="Mosaic SDK">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Sending 1 to the outsider, who is not on the allowlist</span></div>
<div className="sol-run-out">

```text Output
{
  discriminator: 1,
  bump: 255,
  enablePermissionlessThaw: true,
  enablePermissionlessFreeze: false,
  mint: '653XZoSFLEb7BuezYeLTiq5KBsdFDHZ71MfsybEzHr9G',
  freezeAuthority: 'Grr9mjov4Ao553eJfERUuGK7GPv2BmJsnsS7xxdcWjXF',
  gatingProgram: 'GATEzzqxhJnsWF6vHRsgtixxSB8PaQdcqGEVTEHWiULz'
}
EAEXfee6dPx7myBsnb6e4CEVgt9APZWdvYwYi54e7t4E
Failed: Program GATEzzqxhJnsWF6vHRsgtixxSB8PaQdcqGEVTEHWiULz failed: custom program error: 0x1002
```

</div>
</div>

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

```ts
// npx tsx transfer.ts <recipient> <amount>
import { address } from "@solana/kit";
import {
  fetchMint,
  findAssociatedTokenPda,
  getTransferCheckedInstruction,
  TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import { arg, env, loadSigner, rpc, send, toBaseUnits } from "./common";
import { openThroughGate } from "./gate";

// The holder signs and pays for its own transfer.
const holder = await loadSigner("demo-holder");
const mint = address(env("MINT"));
const list = address(env("LIST"));
const { data } = await fetchMint(rpc, mint);

const [source] = await findAssociatedTokenPda({
  mint,
  owner: holder.address,
  tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// The thaw is where an unlisted recipient fails: the gate rejects the owner
// and the whole transaction is dropped before any token moves.
const { tokenAccount: destination, instructions } = await openThroughGate(
  holder,
  mint,
  address(arg(1, "the recipient wallet")),
  list,
);
await send(holder, [
  ...instructions,
  getTransferCheckedInstruction({
    source,
    mint,
    destination,
    authority: holder,
    amount: toBaseUnits(arg(2, "the amount"), data.decimals),
    decimals: data.decimals,
  }),
]);
```

<div className="sol-run" data-run="paths/assets/gated-token/transfer-blocked" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Sending 1 to the outsider, who is not on the allowlist</span></div>
<div className="sol-run-out">

```text Output
Failed: Program GATEzzqxhJnsWF6vHRsgtixxSB8PaQdcqGEVTEHWiULz failed: custom program error: 0x1002
```

</div>
</div>

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

```ts
// npx tsx transfer.ts <recipient> <amount>
import { PublicKey } from "@solana/web3.js";
import {
  findAssociatedTokenPda,
  getMintDecoder,
  getTransferCheckedInstruction,
  TOKEN_2022_PROGRAM_ADDRESS,
} from "@solana-program/token-2022";
import {
  addressOf,
  arg,
  connection,
  env,
  loadKeypair,
  send,
  toBaseUnits,
} from "./common";
import { openThroughGate } from "./gate";

// The holder signs and pays for its own transfer.
const holder = await loadKeypair("demo-holder");
const mint = addressOf(env("MINT"));
const list = addressOf(env("LIST"));
const mintAccount = await connection.getAccountInfo(new PublicKey(mint));
const { decimals } = getMintDecoder().decode(mintAccount!.data);

const [source] = await findAssociatedTokenPda({
  mint,
  owner: holder.publicKey.toBase58(),
  tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
});
// The thaw is where an unlisted recipient fails: the gate rejects the owner
// and the whole transaction is dropped before any token moves.
const { tokenAccount: destination, instructions } = await openThroughGate(
  holder,
  mint,
  addressOf(arg(1, "the recipient wallet")),
  list,
);
await send(
  [holder],
  [
    ...instructions,
    getTransferCheckedInstruction({
      source,
      mint,
      destination,
      authority: holder,
      amount: toBaseUnits(arg(2, "the amount"), decimals),
      decimals,
    }),
  ],
);
```

<div className="sol-run" data-run="paths/assets/gated-token/transfer-blocked" data-tab="Web3.js v3">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Sending 1 to the outsider, who is not on the allowlist</span></div>
<div className="sol-run-out">

```text Output
Failed: Program GATEzzqxhJnsWF6vHRsgtixxSB8PaQdcqGEVTEHWiULz failed: custom program error: 0x1002
```

</div>
</div>

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

```rust
// cargo run --release --bin transfer -- <recipient> <amount>
use anyhow::Result;
use gated_token::{
    acl, arg, arg_pubkey, ata, env, load_keypair, mint_decimals, rpc, send, to_base_units,
    TOKEN_2022,
};
use solana_sdk::signature::Signer;
use spl_token_2022_interface::instruction::transfer_checked;

#[tokio::main]
async fn main() -> Result<()> {
    let rpc = rpc();
    // The holder signs and pays for its own transfer.
    let holder = load_keypair("demo-holder")?;
    let mint = env("MINT")?;
    let list = env("LIST")?;
    let recipient = arg_pubkey(1, "the recipient wallet")?;
    let decimals = mint_decimals(&rpc, &mint).await?;

    // The thaw is where an unlisted recipient fails: the gate rejects the
    // owner and the whole transaction is dropped before any token moves.
    let (destination, mut instructions) =
        acl::open_through_gate(&rpc, &holder.pubkey(), &mint, &recipient, &list).await?;
    instructions.push(transfer_checked(
        &TOKEN_2022,
        &ata(&mint, &holder.pubkey()),
        &mint,
        &destination,
        &holder.pubkey(),
        &[],
        to_base_units(&arg(2, "the amount")?, decimals)?,
        decimals,
    )?);
    send(&rpc, &[&holder], &instructions).await
}
```

<div className="sol-run" data-run="paths/assets/gated-token/transfer-blocked" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Sending 1 to the outsider, who is not on the allowlist</span></div>
<div className="sol-run-out">

```text Output
Failed: Program GATEzzqxhJnsWF6vHRsgtixxSB8PaQdcqGEVTEHWiULz failed: custom program error: 0x1002
```

</div>
</div>

</Tab>
</Tabs>

It fails. The transfer creates the outsider's token account and inserts a
permissionless thaw for it; Token ACL hands the decision to the gate program,
and the gate rejects a wallet that is not on the list with custom program error
`0x1002` (4098). The transfer instruction never runs, and because the RPC node
rejects the transaction in simulation, it never lands and no fee is charged.

Now add the outsider to the list with `allowlist-add` and run the same transfer
again:

```bash Terminal
npx tsx allowlist-add.ts $OUTSIDER
npx tsx transfer.ts $OUTSIDER 1
```

In Rust, run `cargo run --release --bin allowlist-add -- $OUTSIDER` and then
`cargo run --release --bin transfer -- $OUTSIDER 1`. The transfer succeeds and
prints its signature. The only change was the onboarding decision recorded on
the list.

Leave the outsider on the list. Removing a wallet is the
[offboarding step](/developers/docs/tokenization/tutorials/issuing/operate-the-token#offboard-a-holder)
at the end of the next page, and it does more than reverse the add: it also
freezes the wallet's existing token account.

</Step>

</Steps>

## Blocklists

The same gate program supports a blocklist instead of an allowlist, where every
address qualifies except the ones you name. An allowlist fails closed: an
address holds the token only after it has been added. A blocklist fails open:
an address holds the token unless it has been named. A blocklist suits cases
where open holding is the intended design and the list acts as a sanctions
overlay. [Token ACL](/developers/docs/tokenization/token-acl) shows how to
create one.

## Next steps

- [Operate the token](/developers/docs/tokenization/tutorials/issuing/operate-the-token):
  freeze, pause, force a transfer, burn, and offboard a holder
