Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-go

Go SDK library and RPC client for the Solana Blockchain

View on GitHub

26 documents · Updated Nov 16, 2026

docs / token-programs

Token, Token-2022, and associated token APIs

The token APIs model Solana token mints, token accounts, and the instructions that change them. They cover the classic SPL Token program, the Token-2022 program with extensions, RPC views of token data, and associated-token-account setup and recovery. The classic package also covers p-token utility operations for batch execution, amount conversion, account sizing, and native SOL handling. Token-2022 also exposes confidential transfer, confidential fee, and confidential mint and burn flows that coordinate encrypted values with proof verification. This page complements Program instruction builders and relates to System and stake programs, Lookup table and auxiliary programs, and ZK ElGamal proof program.

Program roles

The token system separates token rules from account setup. A mint defines a token supply and its authorities. A token account holds units of one mint for one owner. The associated token account program creates the standard token account address for a wallet and mint. The two token program packages use the same core account model but target different on-chain program IDs. References: programs/…/instructions.go• L15-45, programs/…/accounts.go• L24-41, programs/…/accounts.go• L166-193, programs/…/instructions.go• L15-42, programs/…/instructions.go• L28-54

The classic package targets the original SPL Token program. The Token-2022 package targets the Token Extensions program and adds extension-aware instructions and state. Each instruction carries a program identity when it is turned into a Solana instruction, so a transaction can send the operation to the intended program. A per-instruction program ID override lets callers select that identity without changing shared package state. References: programs/…/instructions.go• L34-46, programs/…/instructions.go• L270-297, programs/…/instructions.go• L351-356, programs/…/instructions.go• L35-48, programs/…/instructions.go• L304-322

Core token lifecycle

The core lifecycle moves from mint creation to account creation and then to token movement. Authorities can mint, burn, freeze, thaw, delegate, revoke, or change authority. Checked variants also carry the mint decimals so a signer can verify the unit scale while building a transaction. References: programs/…/instructions.go• L49-176, programs/…/instructions.go• L50-120

The flow below shows how the packages fit into a common wallet or application action. The system program usually creates the account storage first, while the token program initializes and controls the token state.

flowchart LR
    A[Mint definition] --> B[Mint account]
    B --> C[Token account for owner]
    C --> D[Transfer or mint tokens]
    D --> E[Balance and supply queries]
    C --> F[Close or unwrap account]
    G[Associated token account program] --> C
    H[Token-2022 extensions] --> B
    H --> C

The builders expose both fluent field setters and validation before build. They also preserve account metadata for transaction assembly and instruction decoding. Use the package matching the mint owner; a token account owned by Token-2022 is not interchangeable with one owned by the classic program. References: programs/…/Transfer.go• L20-115, programs/…/InitializeMint.go• L20-130, programs/…/Transfer.go• L20-115, programs/…/InitializeMint.go• L20-130

Instruction builders

The instruction builders turn token actions into the common Solana instruction shape: a program ID, ordered account metadata, and encoded instruction data. The classic and Token-2022 packages register decoders so instructions from transactions can be mapped back to their typed variants. Builders and decoders use the same pointer form for instruction implementations, so code can inspect locally built and decoded instructions through the same type assertion. References: programs/…/instructions.go• L266-380, programs/…/instructions.go• L417-453, programs/…/impl_pointer_consistency_test.go• L25-66, programs/…/instructions.go• L332-534

Core builder groups map to the main token responsibilities:

GroupPurpose
InitializationCreate mint, token account, or multisig state
Supply and balanceMint, burn, transfer, and sync wrapped SOL
AuthorityApprove or revoke delegates and set authorities
Account stateFreeze, thaw, and close token accounts
Checked actionsConfirm mint identity and decimals during sensitive amount operations
Utility actionsQuery account size, convert token amounts, initialize immutable ownership, and manage native SOL
Batch executionRun several supported token instructions in one p-token call

Builders support multisig authority by placing the authority account and its signer accounts in the required order. Validation checks required accounts and signer capacity, but the on-chain program still decides whether the authority is valid for the target account. References: programs/…/types.go• L21-49, programs/…/Approve.go• L25-112, programs/…/SetAuthority.go• L25-133, programs/…/Reallocate.go• L14-35, programs/…/UnwrapLamports.go• L98-143

The classic package also exposes an instruction-level program-ID override. This lets one process build classic Token and Token-2022-compatible instructions without changing shared package state. The Token-2022 package provides the same per-instruction model. References: programs/…/instructions.go• L270-297, programs/…/instructions.go• L351-356, programs/…/instructions.go• L304-322

The p-token additions use non-contiguous instruction IDs that are decoded through a separate map. Batch carries each child instruction's account count and data length, then flattens the child accounts for the outer call. It does not support nested batches, and each child account list and data payload must fit in the one-byte batch header fields. References: programs/…/instructions.go• L192-204, programs/…/instructions.go• L342-349, programs/…/Batch.go• L27-45, programs/…/Batch.go• L85-101, programs/…/Batch.go• L154-216

Token-2022 confidential features use extension wrappers with a sub-instruction ID and typed payload. The shared confidential builder path adds the authority and multisig signers, while typed decoders reject unknown sub-instructions and payloads with the wrong size. References: programs/…/confidential_common.go• L22-65, programs/…/confidential_common.go• L101-132, programs/…/ConfidentialTransferExtension.go• L48-107, programs/…/ConfidentialMintBurnExtension.go• L30-86

Token-2022 also provides higher-level confidential client helpers. They take decoded confidential account state and the needed keys, then build proof data and ready-to-submit instruction sequences for transfer, withdrawal, confidential mint and burn, and confidential fee operations. An operation uses inlined proofs when all proof accounts are absent, or context-state proofs when all are supplied; mixed proof locations are rejected. References: programs/…/confidential_transfer_account_info.go• L22-30, programs/…/confidential_mint_burn_client.go• L62-111, programs/…/confidential_transfer_fee_client.go• L17-67, programs/…/confidential_transfer_client_test.go• L105-134

Token utility instructions

The classic token package includes small instructions that return computed token values through Solana return data instead of writing a token account. Account sizing returns a little-endian byte count for a mint. Amount conversion returns either a UTF-8 UI amount string or a little-endian raw amount. Callers must read and parse the simulation or transaction return data. References: programs/…/GetAccountDataSize.go• L27-32, programs/…/GetAccountDataSize.go• L101-113, programs/…/AmountToUiAmount.go• L27-32, programs/…/AmountToUiAmount.go• L126-138, programs/…/UiAmountToAmount.go• L27-32, programs/…/UiAmountToAmount.go• L128-140

Immutable-owner initialization is a compatibility instruction for associated-token-account setup. It must occur before token-account initialization and is a no-op in this version of the classic program. References: programs/…/InitializeImmutableOwner.go• L26-32, programs/…/InitializeImmutableOwner.go• L38-72

Account and state codecs

The codecs turn on-chain bytes into typed mint, token-account, and multisig state and can encode those values again. A mint carries supply, decimals, initialization state, and optional authorities. A token account carries its mint, owner, amount, delegate, state, native-SOL marker, delegated amount, and close authority. References: programs/…/accounts.go• L24-41, programs/…/accounts.go• L166-193, programs/…/accounts.go• L10-27, programs/…/accounts.go• L150-175

Token-2022 keeps the same base state for accounts without extensions. Extended state adds an account-type marker and a list of extension records. The typed extended codecs expose known mint and token-account extensions while retaining unknown records so data from a newer program version can survive a decode and encode cycle. References: programs/…/extension_account.go• L13-71, programs/…/extension_account.go• L81-99, programs/…/extension_account.go• L494-518

The lower-level extension helpers serve two needs. ParseExtensions gives callers raw type and data records. The full mint and account decoders validate the layout and map those records to typed state. This split supports both inspection of new extension types and safe use of known state. References: programs/…/extension_states.go• L539-649, programs/…/extension_account.go• L101-163, programs/…/extension_account.go• L222-251

Confidential client account info is a separate view over decoded confidential state. It provides the values needed to build a client operation: pending and available balances for transfer accounts, the current encrypted supply and cache for confidential mints, and the encrypted destination state after a change. It also creates the proof data for operations such as transfer, withdrawal, apply-pending-balance, confidential mint, and confidential burn while checking for insufficient funds and balance overflow. References: programs/…/confidential_transfer_account_info.go• L14-91, programs/…/confidential_transfer_account_info.go• L95-186, programs/…/confidential_mint_burn_account_info.go• L14-110

Token-2022 extensions

Token-2022 extends the core token lifecycle with optional rules attached to a mint or token account. Extension types state where the rule applies and whether its data has a fixed size. The package includes extension instructions as grouped sub-instructions inside the Token-2022 instruction set. References: programs/…/extension_types.go• L54-93, programs/…/instructions.go• L122-200

The main extension capabilities are:

CapabilitySystem effect
Transfer feesWithhold and later withdraw fees from transfers
Confidential transfersKeep balances and transfer values in encrypted form
Confidential transfer feesEncrypt withheld fees and move them through mint or account withdrawal flows
Confidential mint and burnKeep supply changes under encrypted supply and proof checks
Default account stateGive new token accounts a configured state
Transfer hooksCall a configured program during transfers
Interest-bearing and scaled UI amountsPresent amounts through time or multiplier-based views
Non-transferable and pausable tokensRestrict movement or pause token actions
Delegates and guardsAdd permanent delegation or limit cross-program actions
Metadata and group pointersLink token metadata and group or member records
Permissioned burnRequire a configured authority for burns

Account sizing is part of the extension lifecycle. Callers calculate the mint or token-account size before account creation. If an existing account needs more extension space, the Reallocate instruction expands it and charges a payer for the added rent. References: programs/…/extension_types.go• L119-175, programs/…/GetAccountDataSize.go• L13-21, programs/…/Reallocate.go• L14-35

The package also supplies client-side math for transfer fees, interest-bearing amounts, and scaled UI amounts. These helpers use the same rounding and overflow behavior as the token program so applications can estimate fees and display values before sending an instruction. References: programs/…/extension_math.go• L109-217, programs/…/extension_math.go• L219-285, programs/…/extension_math.go• L318-358

Transfer hooks and several pointer-style extensions accept optional addresses. The instruction codecs preserve the on-chain distinction between an address that is set and an address that is absent, so a nil authority or hook target can be represented without changing the instruction shape. References: programs/…/TransferHookExtension.go• L108-175, programs/…/extension_pubkey_encoding_test.go• L11-67, programs/…/TransferFeeExtension.go• L182-280

Confidential client helpers use the account's encrypted balance and decryptable balance cache to prepare transfers, transfers with fees, withdrawals, pending-balance application, and empty-account checks. They can generate the required proofs when proofs are inlined, or pass ordered context-state accounts when proofs were created earlier. The same operation must use one proof location mode for all of its proofs. References: programs/…/confidential_transfer_account_info.go• L12-169, programs/…/confidential_transfer_client_test.go• L14-114, programs/…/confidential_client_common_test.go• L60-173

Confidential mint and burn adds encrypted supply management to Token-2022. Its lifecycle initializes the mint configuration, updates or rotates the encrypted supply view, mints or burns against confidential balances, and applies a pending burn to the confidential supply. The client helpers reconcile the decryptable supply cache with applied burns before they create new supply values. Mint and burn builders can use three context-state proofs or inline the three verification instructions. Initialization must be paired with mint initialization in the same transaction. References: programs/…/confidential_mint_burn_account_info.go• L14-110, programs/…/confidential_mint_burn_client.go• L12-183, programs/…/confidential_mint_burn_client_test.go• L9-79

Confidential transfer fees add encrypted fee collection to confidential transfers. The API can enable or disable harvesting to the mint, harvest withheld fees from accounts to the mint, and withdraw withheld fees from the mint or selected accounts into a confidential destination balance. The withdraw helper proves that the authority's encrypted fee amount can be re-encrypted for the destination, unless a context-state proof supplies that fact. References: programs/…/confidential_transfer_fee_client.go• L10-128, programs/…/confidential_transfer_fee_client_test.go• L12-85

Confidential transfer instruction data can include zero-knowledge proof material that this package does not create from arbitrary external inputs. The client helpers create the supported proof payloads from the supplied encrypted state and keys, while callers can instead provide proof context accounts. When proofs use sibling instructions, the builders append the matching verification instructions and require their offsets to follow the consuming instruction in order. References: programs/…/confidential_common.go• L135-180, programs/…/confidential_transfer_client.go• L23-112, programs/…/confidential_mint_burn_client.go• L76-111, programs/…/confidential_transfer_fee_client.go• L70-85

Confidential mint and burn and confidential transfer fee clients use the same proof boundary as confidential transfer. A proof may be represented by an inlined verification instruction or by a proof context account, but the consuming Token-2022 instruction must reference the selected location in the expected order. The ZK ElGamal proof program describes the proof instruction boundary. References: programs/…/confidential_client_common_test.go• L107-173, programs/…/confidential_mint_burn_client.go• L103-167, programs/…/confidential_transfer_fee_client.go• L28-67

Confidential transfer key derivation and proof production remain separate contracts. The zkencryption package derives the ElGamal and authenticated-encryption keys, while proof data is built through the confidential proof-data APIs or supplied through compatible proof context accounts. See the ZK ElGamal proof program for the proof instruction boundary. References: programs/…/ConfidentialTransferExtension.go• L31-41, programs/…/confidential_transfer_account_info.go• L136-161

Older confidential balances may use the pre-v1 SHA3-512 derivation. The package keeps separate legacy helpers so applications can reproduce those keys during migration. New key material must use the v1 helpers. Proof generation remains outside this package and must come from a compatible Rust or JavaScript/WASM source. References: programs/…/legacy.go• L12-16, programs/…/legacy.go• L34-77, programs/…/legacy.go• L79-125, programs/…/kdf_vectors.json• L1-100

Token RPC access

The RPC layer exposes token views without requiring callers to assemble raw JSON-RPC requests. It supports supply, largest accounts, one account balance, and account searches by owner or delegate. Owner and delegate searches can narrow results by mint or by token program, which is important when an owner uses both classic and Token-2022 assets. References: rpc/getTokenSupply.go• L23-42, rpc/getTokenLargestAccounts.go• L23-46, rpc/getTokenAccountBalance.go• L23-75, rpc/getTokenAccountsByOwner.go• L24-84, rpc/getTokenAccountsByDelegate.go• L24-116

The token packages also provide a focused mint fetch helper. It queries program accounts for the package's program ID and decodes the classic fixed-size mint shape. Extended Token-2022 mints need extension-aware decoding when their account data is larger than the base mint size. References: programs/…/rpc.go• L28-68, programs/…/rpc.go• L11-51, programs/…/extension_account.go• L81-99

The general RPC package can classify a raw account as a classic or Token-2022 mint by its owner and byte shape. This fast check is useful before selecting a decoder, but it does not replace full state validation. References: rpc/util.go• L5-39

Associated token accounts

An associated token account is the deterministic token account for a wallet and mint. The associated-token-account builders derive that address from the wallet, mint, and token program, then assemble the payer, wallet, mint, system program, and token program accounts needed for creation. References: programs/…/Create.go• L27-50, programs/…/Create.go• L93-143

Use the creation variant that matches the desired behavior:

OperationBehavior
CreateCreates the account and reports an error if it already exists
CreateIdempotentCreates it when absent and succeeds when the existing account has the expected owner
RecoverNestedMoves tokens from an associated account owned by another associated account and closes the nested account

Both create builders accept an explicit token program. This is the bridge for Token-2022 associated accounts because the token program participates in the derived address. Recovery uses the classic token-program address derivation and account set. References: programs/…/instructions.go• L41-54, programs/…/CreateIdempotent.go• L27-53, programs/…/CreateIdempotent.go• L95-144, programs/…/RecoverNested.go• L27-57, programs/…/RecoverNested.go• L91-153

The common setup flow is therefore deterministic: select the mint owner program, derive the matching associated address, choose strict or idempotent creation, and submit the resulting instruction with the payer signature.

sequenceDiagram
    participant App
    participant ATA as Associated token program
    participant Token as Token or Token-2022 program
    participant Wallet

    App->>App: Select mint and token program
    App->>App: Derive associated token address
    App->>ATA: Create or create idempotently
    ATA->>Token: Initialize token account
    Wallet-->>ATA: Payer signature
    ATA-->>App: Associated token account ready

Native SOL operations

Wrapped SOL uses a token account whose balance reflects lamports held by the account. The classic program provides SyncNative to refresh the token amount after lamports move into the account. The p-token implementation adds direct unwrapping and excess-lamport withdrawal, so clients can send lamports to a destination without first creating a temporary associated token account. References: programs/…/instructions.go• L161-203, programs/…/UnwrapLamports.go• L27-39, programs/…/WithdrawExcessLamports.go• L27-47

Unwrapping can move all lamports or a selected amount from a native SOL token account to a destination. Excess-lamport withdrawal applies to a token account, mint account, or multisig account and moves only the balance above the rent-exempt minimum. Both operations use the source authority and support multisig signers. References: programs/…/UnwrapLamports.go• L41-54, programs/…/UnwrapLamports.go• L176-208, programs/…/WithdrawExcessLamports.go• L34-48, programs/…/WithdrawExcessLamports.go• L116-132

Change checklist

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

  • Keep classic and Token-2022 instruction variant IDs and decoder registrations aligned with the on-chain program interfaces.
  • When an extension changes its state or size, update the extension type map, typed state codec, account-length calculation, and any grouped extension instruction.
  • Preserve the token program in associated-address derivation and in the associated-token-account instruction accounts. A program mismatch creates or queries a different address.
  • Keep RPC owner and delegate filters mutually exclusive for mint and program selection. The selected program must match the account owner expected by downstream decoding.
  • Keep Token-2022 base-state and extension-aware decoding paths distinct. Fixed-size mint queries do not describe extended mint data.
  • Keep each confidential extension's sub-instruction IDs, typed payload codecs, and proof-account layout aligned with the on-chain interface.
  • Keep client helpers consistent about proof location. An operation that accepts context-state accounts must either use all required context proofs or generate all required inline proofs.
  • When a confidential builder supports proof instruction offsets, update the appended verification order and the context-state account path together. Keep the Rust parity vectors in step with both.
  • Treat confidential-transfer key derivation and proof generation as separate contracts. Keep the v1 key scheme compatible with the Rust and JavaScript/WASM SDKs, and retain legacy derivation only for migration of older encrypted balances.
  • Preserve the source-account placement and source-count limit for confidential fee withdrawals. Multisig signers must remain before source accounts.
  • Keep p-token instruction IDs in pTokenInstructionMap and in InstructionIDToName when adding or changing p-token operations.
  • Keep batch account counts, child data lengths, child decoder support, and flat account redistribution aligned. A change in one part can break decoded child instructions without changing the outer instruction shape.
  • Keep return-data parsers aligned with the exact encoding and type returned by amount conversion and account-size instructions.
  • Keep builder Impl values as pointers matching decoded instruction types. Callers use the same type assertion for built and decoded instructions.

Important failure modes

TriggerConsequenceGuard
The mint owner and selected token program do not matchThe instruction fails or the application derives the wrong associated accountRead the mint owner and pass the same program ID through builders and RPC filters
A strict associated-account create runs when the account already existsThe transaction reports an existing-account errorUse CreateIdempotent for retry-safe setup
Extension space is omitted or too smallMint or account creation cannot store the selected extensionsCalculate the required size before creation and use Reallocate for supported existing accounts
Extended data has a bad account marker, truncated TLV, duplicate, or wrong extension kindFull Token-2022 decoding rejects the accountTreat decode errors as invalid state and do not use a partial typed value as trusted state
A transfer fee or UI conversion exceeds supported arithmeticThe helper returns a calculation or UI amount error instead of a safe amountCheck returned errors and use the same epoch and extension state as the chain
An amount or account-size utility return value is read with the wrong encodingThe caller displays an invalid amount or allocates the wrong account sizeUse the matching parser and treat invalid UTF-8 or short little-endian data as an error
A batch contains a nested instruction, empty child data, or more than 255 child accounts or data bytesBatch validation or encoding fails, or the on-chain p-token entrypoint rejects the callValidate children before build and keep each child within the one-byte header limits
A decoded batch cannot distribute its flat account list to a childThe child instruction has missing or mis-grouped accountsPreserve per-child account counts and use child implementations that accept account assignment
A builder stores a value implementation while decoding returns a pointer implementationType assertions work for only one construction path and may fail at runtimeKeep all builders and decoders on the same pointer type
An optional authority or hook target uses the wrong absent-address encodingThe on-chain program reads a different authority or hook configurationUse the builder's optional values and preserve the interface encoding when using raw instructions
A confidential client mixes context-state and inline proofs, or leaves a required proof account unsetThe helper rejects the operation or the consuming instruction points to the wrong proof locationSupply every required context proof or omit every proof account so the helper can inline the full proof set
A confidential proof location is unset, has the wrong offset, or uses a typed nil proofThe builder rejects the instruction or the proof does not verify in the intended transaction positionUse a validated context account or place sibling proofs at the required sequential offsets
Confidential-transfer keys use the wrong derivation scheme or are paired with proof data from another key setThe Token-2022 confidential instruction cannot pass on-chain verification or old encrypted balances cannot be decryptedUse v1 derivation for new keys, use legacy helpers only for old data, and derive the ElGamal and AE keys together when possible
Confidential-transfer proof data is absent or made by an incompatible sourceThe Token-2022 confidential instruction cannot pass on-chain verificationUse a compatible proof producer and the deterministic keys derived for the token account
A confidential mint or burn uses stale supply or account stateThe new encrypted value or proof does not describe the on-chain balanceBuild account info from current decoded state and apply pending changes in the required order
A confidential fee withdrawal uses an incorrect proof position or source-account orderThe withdrawal cannot verify or the account metas do not match the program contractUse the outer builder only for a directly following proof, and keep multisig signers before source accounts in account withdrawals
A confidential fee withdrawal lists more than 255 source accountsThe instruction cannot encode the source-account countSplit the operation into multiple withdrawals
A nested associated account is recovered with mismatched mint relationshipsRecovery derives different accounts or the on-chain checks failSupply the wallet, nested mint, and owner mint that define the nested ownership chain

Key files

FileWhy to read it
programs/…/instructions.goCore classic Token instruction set, p-token instruction dispatch, decoding, and program selection
programs/…/Batch.gop-token batch execution and child account/data framing
programs/…/GetAccountDataSize.goAccount-size return-data instruction and parser
programs/…/AmountToUiAmount.goRaw amount to UI amount return-data instruction
programs/…/UiAmountToAmount.goUI amount to raw amount return-data instruction
programs/…/InitializeImmutableOwner.goAssociated-token-account compatibility instruction
programs/…/UnwrapLamports.goDirect native SOL unwrapping
programs/…/WithdrawExcessLamports.goRent-excess withdrawal from token-owned account types
programs/…/impl_pointer_consistency_test.goContract that built and decoded instructions expose matching pointer types
programs/…/accounts.goClassic mint and token-account state model
programs/…/instructions.goCore and extension-aware Token-2022 instruction set
programs/…/extension_types.goExtension categories, account applicability, and size rules
programs/…/extension_account.goFull extended mint and token-account decode and encode flow
programs/…/extension_states.goTyped extension state and raw TLV model
programs/…/extension_math.goClient-side fee and UI amount calculations
programs/…/ConfidentialTransferExtension.goConfidential transfer sub-instruction boundary and typed decoding
programs/…/ConfidentialMintBurnExtension.goConfidential encrypted-supply sub-instruction boundary
programs/…/ConfidentialTransferFeeExtension.goConfidential fee sub-instruction boundary and typed decoding
programs/…/confidential_common.goShared confidential instruction decoding, authority accounts, and encrypted balance calculations
programs/…/confidential_transfer_account_info.goClient-side confidential transfer, withdrawal, pending-balance, and empty-account state calculations
programs/…/confidential_mint_burn_client.goReady-to-submit confidential mint, burn, supply rotation, and pending-burn helpers
programs/…/confidential_transfer_fee_client.goConfidential fee harvest, configuration, and withdrawal helpers
programs/…/confidential_transfer_client.goConfidential transfer, withdrawal, account configuration, and proof-location helpers
programs/…/confidential_keys.goJoint derivation of confidential-balance keys from one signer signature
programs/…/legacy.goMigration support for keys made with the pre-v1 derivation
rpc/getTokenAccountsByOwner.goToken-account discovery by owner and program or mint filter
rpc/getTokenAccountBalance.goSingle token-account balance view
rpc/util.goFast mint classification for classic and Token-2022 accounts
programs/…/Create.goDeterministic associated-account creation and token-program selection
programs/…/CreateIdempotent.goRetry-safe associated-account creation
programs/…/RecoverNested.goNested associated-account recovery and closure