Introducing a new way to review your PRs.

Read the announcement

solana-foundation / program-examples

A repository of Solana program examples

View on GitHub

19 documents · Updated Nov 23, 2026

docs / token-2022-extensions

Token-2022 extension patterns

Token-2022 adds optional rules and data to the Solana token model. These examples show how extensions shape mint and token-account creation, transfer policy, authority design, metadata, and client transactions in ways that differ from the original token program. See Token program examples for the wider token example set.

Extension model

An extension is a feature attached to a Token-2022 mint or token account. It adds data or a rule that the Token-2022 program applies to token actions.

Mint extensions

Mint extensions define policy for the whole asset. They can set a fee, call a transfer hook, set a default account state, assign a delegate, store metadata, group related assets, or add a close authority. The mint therefore carries both the base token settings and the extra rules that its token accounts must follow.

References: tokens/…/initialize.rs• L35-75 tokens/…/test_group.rs• L42-51 tokens/…/create_mint.rs• L20-31

Token-account extensions

Token-account extensions apply a rule to one token account. Memo Transfer requires a memo for incoming transfers. Immutable Owner fixes the account owner after setup. CPI Guard limits selected actions made through another program. These accounts need space for their extension data.

References: tokens/…/test_memo_transfer.rs• L101-161 tokens/…/create_token_account.rs• L25-87 tokens/…/test.ts• L113-130 tokens/…/cpi_transfer.rs• L21-28

Default account state

Default Account State is a mint rule that sets the starting state of each new token account. The example first creates accounts as frozen, then changes the default to initialized for accounts created later. Existing accounts keep the state they had when they were created.

References: tokens/…/test_default_account_state.rs• L70-129 tokens/…/test.ts• L89-109 tokens/…/create_mint.rs• L68-101

Combined extensions

One mint can carry several compatible extensions. The multiple-extension example combines Mint Close Authority with Non-Transferable. The asset cannot move between accounts but can still be closed by its configured authority.

References: tokens/…/create_mint.rs• L21-30 tokens/…/test.ts• L84-109 tokens/…/lib.rs• L34-85

Mint and account lifecycle

Token-2022 must know the complete account shape before it initializes the base state. Creation therefore starts with the selected extensions and their required size, not with the base mint or account alone.

Mint creation

The mint creator chooses the extensions, allocates enough space for the base mint and extension data, funds the account, and assigns ownership to Token-2022. The extension settings are initialized before the base mint is initialized.

References: tokens/…/create_mint.rs• L61-108 tokens/…/create_mint.rs• L43-74 tokens/…/create_mint.rs• L52-93

The following diagram shows the common Token-2022 mint sequence.

flowchart TD
    A[Choose mint extensions] --> B[Calculate extended mint size]
    B --> C[Create Token-2022-owned mint]
    C --> D[Initialize extensions]
    D --> E[Initialize base mint]
    E --> F[Create token accounts]

Token-account creation

An account with an account extension must be allocated for its extended shape and owned by Token-2022. The account extension and base token account are initialized in the order required by that extension. Immutable Owner must be set before the base account, while Memo Transfer is enabled after the base account exists.

References: tokens/…/create_token_account.rs• L40-75 tokens/…/create_token_account.rs• L48-84 tokens/…/test_memo_transfer.rs• L101-119 tokens/…/test.ts• L90-129

The following diagram shows the account setup order for an account-level extension.

flowchart TD
    A[Choose account extension] --> B[Allocate extended Token-2022 account]
    B --> C[Initialize extension at its required point]
    C --> D[Initialize or use base token account]
    D --> E[Enforce extension rule]

Extension order

Most mint extensions must be initialized before InitializeMint. Token-2022 rejects late mint-extension setup after the mint is initialized. Account extensions do not all share that rule, so each account extension defines its own valid setup order.

References: tokens/…/create_mint.rs• L69-102 tokens/…/create_token_account.rs• L63-84 tokens/…/create_token_account.rs• L55-75

Mint closure

Mint Close Authority gives a separate authority permission to close the mint and receive its rent balance. It controls mint-account lifetime. It does not replace mint authority and does not itself change transfer rules.

References: tokens/…/test_mint_close_authority.rs• L48-93 tokens/…/create_mint.rs• L20-23 tokens/…/test.ts• L101-108

Transfer behavior

Token-2022 transfer behavior comes from the mint and the source and destination accounts. A client or program must use an instruction that understands the active extensions and must provide any accounts that those extensions need.

Transfer fees

Transfer Fee Config changes a transfer into a sent amount, a recipient amount, and a withheld fee. The recipient receives the amount after the fee. The withheld amount stays on token accounts until an authorized flow harvests it to the mint and withdraws it. The fee authority can update the schedule within the configured limits.

References: tokens/…/test_transfer_fee.rs• L125-175 tokens/…/create_mint.rs• L70-108 tokens/…/test.ts• L98-111

Transfer hooks

A Transfer Hook calls a configured program during a token transfer. The hook can enforce an external rule such as a wallet switch or an allow/block list. It can also update state or perform a related token action. Token-2022 supplies the transfer accounts and the extra accounts declared for the mint.

References: tokens/…/transfer_hook.rs• L16-71 tokens/…/lib.rs• L40-78 tokens/…/README.md• L6-26

The following diagram shows how a hook becomes part of the transfer path.

sequenceDiagram
    participant C as Client
    participant T as Token-2022
    participant H as Transfer hook
    participant A as Token accounts
    C->>T: Transfer with hook accounts
    T->>H: Execute hook
    H->>H: Check policy and hook state
    alt Policy allows transfer
        H-->>T: Success
        T->>A: Apply balance change
    else Policy rejects transfer
        H-->>C: Error
    end

Transfer-hook account resolution

The extra-account list is a per-mint account that tells the transfer path which accounts the hook needs. A client that omits those accounts can fail even when the token accounts are valid. The list can describe fixed accounts or accounts derived from the transfer context, such as the sending wallet or data in a token account.

References: tokens/…/initialise_extra_account_metas_list.rs• L32-82 tokens/…/transfer_hook.rs• L34-46 tokens/…/lib.rs• L124-168 tokens/…/readme.md• L7-16

Transfer restrictions

Non-Transferable prevents tokens from moving between token accounts. Memo Transfer adds a memo condition to an enabled account. CPI Guard blocks selected token actions when another program tries to perform them. These extensions make a normal-looking transfer depend on mint or token-account policy. The Memo Transfer example enables the incoming-memo rule after account initialization, so a later transfer needs a memo earlier in the same transaction. The CPI Guard example shows an owner-authorized transfer blocked through CPI while the guard is enabled, then allowed after a direct disable instruction.

References: tokens/…/create_mint.rs• L20-23 tokens/…/create_token_account.rs• L63-84 tokens/…/test.ts• L190-229 tokens/…/cpi_transfer.rs• L21-28 tokens/…/test.ts• L177-217

Authority and policy patterns

Token-2022 separates control of token supply, extension settings, account state, and recovery actions. This lets an issuer express policy without putting every operation under the same key.

Mint and extension authorities

The mint authority controls supply. Extensions can add their own authorities, such as fee configuration, fee withdrawal, transfer-hook, close, or interest-rate authorities. The authority for the requested operation must be checked directly.

References: tokens/…/create_mint.rs• L99-108 tokens/…/create_mint.rs• L89-102 tokens/…/create_mint.rs• L24-31

Permanent delegation

Permanent Delegate gives one configured delegate lasting authority over token accounts for the mint. The pattern supports issuer actions such as burning tokens even when a token-account owner has not granted a normal delegate.

References: tokens/…/create_mint.rs• L20-28 tokens/…/test.ts• L98-105

Interest-bearing tokens

Interest Bearing Config stores a mint-level rate and its authority. Token-2022 uses the stored rate and time to report a changed UI amount without changing the raw token balance held by an account.

References: tokens/…/test_interest_bearing.rs• L32-41 tokens/…/create_mint.rs• L32-40 tokens/…/test.ts• L97-108

Metadata and asset patterns

Token-2022 can keep asset identity and custom fields close to the mint. The examples use this model for NFTs, mutable asset data, and relations between grouped assets.

Metadata pointers

Metadata Pointer identifies where metadata lives. The NFT example points the mint to itself and stores the name, symbol, URI, and extra fields in the mint's extended data. This keeps the asset description and its Token-2022 mint in one account.

References: tokens/…/test_mint_nft.rs• L69-90 tokens/…/test_metadata.rs• L93-148 tokens/…/README.md• L27-39

NFT supply control

The NFT flow creates one token in the owner's Token-2022 associated token account and removes the mint authority after minting. The metadata describes the asset while the authority change makes the one-token supply final.

References: tokens/…/test_mint_nft.rs• L35-67 tokens/…/test_mint_nft.rs• L69-90 tokens/…/README.md• L27-39

Metadata lifecycle

The Token Metadata extension supports updates to standard fields and custom key-value fields. Its update authority can later be removed, after which the metadata becomes fixed. The program can also return the stored metadata as instruction return data.

References: tokens/…/lib.rs• L8-30 tokens/…/test_metadata.rs• L93-148

Group pointers

Group Pointer links a mint to a group address and an authority. It lets a Token-2022 mint identify a related asset group while keeping that relationship in the mint's extension data.

References: tokens/…/test_group.rs• L42-51

Instruction and client considerations

Token-2022 keeps many base token concepts but requires explicit program and account choices when extensions are present. The main integration risk is a mismatch between the mint's extension policy and the accounts or instruction form supplied by the client.

Token program selection

A Token-2022 mint and its token accounts are owned by the Token-2022 program. Associated token address derivation and creation therefore include that program identity. A client that uses the original token program can derive the wrong account or fail validation.

References: tokens/…/test_basics.rs• L37-61 tokens/…/test_mint_nft.rs• L35-56 tokens/…/test.ts• L70-79

Extension-aware instructions

Clients must select the instruction form that matches the mint. Fee transfers need fee-aware amount handling. Hook transfers need the resolved extra accounts. Account setup must also follow each extension's initialization contract. A base-token instruction is not a safe substitute when Token-2022 requires extra data or policy checks.

References: tokens/…/test_transfer_fee.rs• L125-158 tokens/…/transfer_hook.rs• L16-46 tokens/…/test.ts• L194-214 tokens/…/test.ts• L193-220

Client state decoding

Token-2022 account data contains base state plus extension data. Clients should decode the mint or token account with an extension-aware decoder and inspect the active extensions before building a transaction. The native and Pinocchio examples validate both the Token-2022 owner and the decoded extension state.

References: tokens/…/test.ts• L89-109 tokens/…/test.ts• L113-130 tokens/…/test.ts• L85-108 tokens/…/test.ts• L122-142

Cross-program setup

Programs often set up Token-2022 state through cross-program invocations. This works for many mint and extension operations, but not all. CPI Guard is the key exception in these examples because its setup and update operations are restricted from CPI and must use direct supported instructions.

References: tokens/…/test_cpi_guard.rs• L102-120 tokens/…/cpi_transfer.rs• L21-28 tokens/…/test.ts• L195-217 tokens/…/initialize.rs• L33-39

Extension composition

Extensions can depend on one another. A hook may use a wallet policy account, a permanent delegate, or immutable account state. A default-frozen account may also need an explicit state update before a user can transfer. Treat the complete extension set as one contract for account creation, authority checks, and transaction assembly.

References: tokens/…/transfer_hook.rs• L41-55 tokens/…/lib.rs• L151-168 tokens/…/create_mint.rs• L21-30

Extension catalog

The examples cover policy, accounting, metadata, and asset-group patterns. Use this table to match a product need to the extension behavior.

Extension patternMain effectData location
Transfer Fee ConfigDeducts a fee and stores withheld amounts for later collectionMint and token accounts
Transfer HookRuns an external rule during transfersMint plus hook accounts
Non-TransferablePrevents token movementMint
Default Account StateSets the initial state of new token accountsMint
Memo TransferRequires a memo for enabled token-account transfersToken account
Interest Bearing ConfigStores a rate and changes reported UI amounts over timeMint
Permanent DelegateGives a lasting delegate authority over mint accountsMint
Mint Close AuthorityAllows an authority to close the mintMint
Metadata Pointer and Token MetadataStores asset identity and custom fields near the mintMint
Group PointerLinks a mint to a related group addressMint
Immutable OwnerPrevents a token-account owner from changingToken account
CPI GuardRestricts selected token actions made through CPIToken account

Change checklist

When these files or sections are changed, remember to consider these:

  • When a mint extension changes, update the account-size calculation and the setup order together. A valid base mint can still be too small or have an uninitialized extension.
  • When an account extension changes, review the account size, its initialization order, and the later instructions that the extension can reject.
  • When a transfer hook's required accounts change, update the per-mint extra-account list and any client transfer builder that assembles the hook call. Migrate existing lists when their layout changes.
  • When an extra account is derived from transfer context, review the account indexes and seed inputs in both the list and the hook account layout.
  • When a shared allow/block list changes state or mode, update the extra-account setup for every affected mint.
  • When a fee schedule or fee authority changes, review the transfer amount semantics and the process that harvests and withdraws withheld fees.
  • When a default account state or memo rule changes, review associated token account creation because users may receive an account that is frozen or needs extra instruction data.
  • When an authority changes, review both the Token-2022 extension authority and any authority stored by the hook or policy program. They are separate contracts.
  • When an extension is added to a mint, review every client and program account constraint that selects the token program and derives associated token accounts.
  • When metadata or group links change, review both the stored pointer and the authority that can update the linked data.

Important failure modes

TriggerConsequenceGuard
Initialize a mint extension after the base mintToken-2022 rejects the extension setupAllocate the full mint size and initialize mint extensions first
Create an account with base-token size onlyThe account cannot hold the selected extensionCalculate size from the full extension set before account creation
Initialize an account extension at the wrong pointToken-2022 rejects setup or the intended account rule is absentFollow the order required by that extension
Use the original token program for a Token-2022 mintThe instruction or account address does not match the mint ownerPass Token-2022 to mint, token-account, and associated-account operations
Send a plain transfer to a transfer-hook mintThe hook or its extra accounts are missing and the transfer failsUse an extension-aware transfer instruction and resolve the mint's extra-account list
Call a transfer hook outside a Token-2022 transferThe hook rejects the call because the account is not marked as transferringCheck the transfer context before applying hook policy
Change a hook's extra accounts without updating old listsExisting mints resolve stale accounts and hook execution fails or checks the wrong walletResize and rewrite each affected per-mint list
Treat the transfer amount as the recipient's net amount for a fee mintThe recipient receives less than the requested amountCalculate and display the withheld fee as part of the transfer result
Transfer from a mint with a restrictive extensionA valid-looking transfer fails because the extension policy rejects itCheck the mint and token-account extensions before constructing the transaction
Change the owner of an Immutable Owner accountToken-2022 rejects the authority changeCreate the account with Immutable Owner and treat its owner as fixed
Initialize or update CPI Guard through another programToken-2022 rejects the CPI-based extension operationPerform the restricted setup through a direct supported instruction

Key files

FileWhy to read it
tokens/…/test_basics.rsShows the Token-2022 mint, associated account, mint, and transfer path with the correct program identity.
tokens/…/create_mint.rsShows how one mint combines close-authority and non-transferable policy.
tokens/…/test_transfer_fee.rsShows fee accounting, withheld amounts, harvesting, withdrawal, and fee updates.
tokens/…/initialise_extra_account_metas_list.rsShows how a mint-specific hook account list describes a wallet policy account.
tokens/…/transfer_hook.rsShows hook account order and a transfer-time wallet policy check.
tokens/…/lib.rsShows extra accounts derived from token-account data and hook-owned state.
tokens/…/readme.mdShows shared block-list policy and the need to reset extra-account modes as the list changes.
tokens/…/create_mint.rsShows frozen default accounts and a later change to the mint default.
tokens/…/test_memo_transfer.rsShows a rule stored on a token account and its memo-dependent transfer behavior.
tokens/…/create_token_account.rsShows extended account creation and enabling required incoming memos after base initialization.
tokens/…/test.tsShows extension-aware account decoding and the same-transaction memo requirement.
tokens/…/test_cpi_guard.rsShows how CPI Guard blocks a program-mediated transfer until disabled.
tokens/…/cpi_transfer.rsShows a Token-2022 transfer through CPI and the mint-owner check before invocation.
tokens/…/test.tsShows the guarded CPI transfer failure, direct disable, successful retry, and invalid-mint rejection.
tokens/…/test.tsShows extended account decoding and rejection of a later owner change.
tokens/…/create_mint.rsShows rate authority setup and a rate update after mint initialization.
tokens/…/test_mint_nft.rsShows a one-token asset with self-referenced metadata and finalized supply.
tokens/…/test_metadata.rsShows metadata updates, authority removal, and returned metadata data.
tokens/…/test_group.rsShows a mint with a group pointer and its stored group authority.

Related pages: Token program examples, Core token operations, NFT and Merkle token flows, and Token exchange and fundraising.