Secure token and payment features
Token and payment features move SOL or tokens between parties while preserving clear asset rules, usable transaction flows, and user trust. This guidance ties the classic Token program and Token-2022 to payment settlement, confidential balances, system transfers, compute planning, transaction v1, and checks that protect value at each boundary.
Value movement model
Value movement starts with a chosen asset model and ends only after the chain confirms the intended state. A client builds instructions for the correct program, selects a transaction version that the wallet and downstream systems support, signs with the required authority, and verifies the resulting account state instead of treating submission as settlement.
flowchart LR
A[Choose asset and program] --> B[Validate accounts and authorities]
B --> C[Build token or SOL instructions]
C --> D[Simulate and set compute budget]
D --> E[Sign and submit]
E --> F[Confirm chain state]
F --> G[Record settlement or report failure]
The surrounding client and program guidance provides the wider transaction and program context. Start with Solana development practices, then use Application and client development, On-chain program development, and Testing and local simulation for adjacent guidance.
References: skills/…/payments.md• L14-21 skills/…/token.md• L61-99 skills/…/security.md• L401-409 skills/…/transactions-v1.md• L8-12
Token program selection
Solana has two separate token programs. The base Token program is the compatibility choice for simple fungible assets. Token-2022 adds extensions such as transfer fees, on-chain metadata, transfer hooks, interest, non-transferability, pausing, and confidential transfers. Mosaic can package extension and authority choices for regulated or allowlisted assets.
Choose the program from the mint's required behavior before deriving accounts or building instructions. A mint belongs to exactly one program, and that program must be used for its token accounts and instructions.
| Need | Program direction |
|---|---|
| Simple token with broad ecosystem support | Base Token |
| Transfer fees or other extensions | Token-2022 |
| Confidential balances or transfers | Token-2022 |
| Lowest compute cost and established compatibility | Base Token |
The token program owner on the mint account is the source of truth for this choice. Both programs use mint and token-account concepts, but their program identities are not interchangeable. The choice changes associated token account derivation, account size, transfer rules, authorities, and the checks a payment or protocol flow must perform. A decoder does not replace the owner check.
For Anchor v1 programs, keep token-related crates on the same compatible release line. Direct dependencies on older SPL crates can pull in a different Solana SDK type set, so use the compatible interface crates or Anchor's compatible re-exports when the program needs token IDs, account types, or instruction builders.
References: skills/…/tokens.md• L10-29 skills/…/token-2022.md• L8-28 skills/…/migrating-v0.32-to-v1.md• L777-856 skills/…/compatibility-matrix.md• L101-124
Token account lifecycle
An associated token account (ATA) is the deterministic account for one owner and one mint under one token program. The token program is part of the ATA derivation, so user-facing flows should use the mint's actual owner program. Anyone can create an ATA for the owner, and idempotent creation is safe when the account may already exist.
Token-2022 account size depends on its extensions. The client must calculate the size and rent from the selected extension set before account creation. A fixed size or fixed rent assumption can make account creation fail or cause a payer to fund more rent than needed. Account extensions can come from the mint, from creation-time setup, or from later owner configuration, so the account must have room for the expected set. On Token-2022, the ATA program also makes the owner immutable. SPL Token ATAs do not provide that same guard.
Mint extensions are fixed when the mint is created in most cases. Their setup must occur before mint initialization, while TokenMetadata and group data are initialized after it. The mint account must be sized for its pre-initialization extensions and funded for any final metadata or group data that will be added later.
References: skills/…/tokens.md• L31-37 skills/…/tokens.md• L71-102 skills/…/token.md• L47-59 skills/…/token-2022.md• L31-75 skills/…/security.md• L521-527
Transfer instruction choice
Checked transfers bind a movement to the intended mint and decimal scale. They are the safe default for value-moving paths because they prevent a client from applying the wrong token or unit interpretation.
Token-2022 extensions can change transfer behavior. Use the checked form for Token-2022 paths and account for any extension that can alter the result:
- Transfer fees reduce the receiver's net amount. Protocol accounting must use the actual balance delta or an explicitly checked fee.
- Transfer hooks run another program during the transfer. The hook and its validation accounts become part of the trust and failure surface.
- Memo transfer rules can reject a transfer that lacks the required memo.
- A permanent delegate can transfer or burn from any public token account for that mint. Accepting such a mint requires an explicit trust decision.
- Pausable, non-transferable, permissioned-burn, and interest or scaled-amount rules can change whether a transfer is allowed or how a balance is shown.
Plain Transfer is deprecated for Token-2022 and fails for several extension-enabled mints. Where a caller must assert the fee as well as the amount, use the checked fee form and pass the hook accounts required by the mint.
References: skills/…/tokens.md• L54-67 skills/…/tokens.md• L113-180 skills/…/token.md• L75-99 skills/…/security.md• L421-437 skills/…/security.md• L441-453 skills/…/security.md• L483-517
Confidential transfer model
Confidential transfers use the Token-2022 confidential-transfer extension to hide balances and transfer amounts while proving on chain that the sender has enough value and that no value is created or destroyed. The owner can read the encrypted balance through keys derived from the owner's keypair and token account.
Confidential accounts have separate public, pending, and available balances. Incoming encrypted funds first become pending. The owner applies them before they become available for another confidential transfer.
The normal lifecycle moves through these states:
- Configure the account with its confidential-transfer keys.
- Deposit public tokens into the pending encrypted balance.
- Apply the pending balance to make it available.
- Transfer from the available balance with the required proofs.
- Withdraw available value back to the public balance when needed.
flowchart LR
P[Public balance] -->|deposit| N[Pending encrypted balance]
N -->|apply pending| V[Available encrypted balance]
V -->|confidential transfer| R[Recipient pending balance]
V -->|withdraw| P
Confidential transfers currently require the TXTX ZK-Edge cluster at https://zk-edge.surfnet.dev/. Keep the cluster endpoint configurable so a later network change does not require a redesign. Proof creation can use substantial client resources, and a transfer can span several transactions because proof context state must be created and later closed. Transaction v1 raises the transaction limit to 4096 bytes and helps carry proof-heavy flows, but it does not remove this multi-transaction context lifecycle.
References: skills/…/confidential-transfers.md• L32-39 skills/…/confidential-transfers.md• L41-73 skills/…/confidential-transfers.md• L109-117 skills/…/confidential-transfers.md• L735-753 skills/…/transactions-v1.md• L8-12 skills/…/transactions-v1.md• L228-233
Confidential transfer safeguards
Confidentiality does not remove the need for balance and authority controls. A compromised owner key exposes the deterministic encryption keys for that owner's token accounts. A mint may also configure an auditor key that can decrypt transfer amounts.
The pending-balance credit limit can stop new incoming credits until the owner applies the pending balance. Product flows must expose this state and give users a way to complete the apply step. The client must also treat proof-context accounts as temporary state and close them after the transfer so rent is not left behind.
References: skills/…/confidential-transfers.md• L59-73 skills/…/confidential-transfers.md• L161-162 skills/…/confidential-transfers.md• L496-582 skills/…/confidential-transfers.md• L735-740
Payment settlement
A payment flow combines an asset transfer with an order or business record. Build common SOL and token transfers with the Kit program interfaces; the token client can derive and create the recipient's associated token account when needed. Attach a memo or unique reference account so the settlement service can locate the transaction for an order. Neither a memo nor a reference prevents a second transfer in a separately signed transaction.
The settlement service must store the signature before submission. If submission times out, it should rebroadcast the same signed transaction or reconcile chain state before asking the user to sign again. Fulfillment must claim the order atomically and require a successful transaction at the commitment level that the business needs.
Payment requests can use Solana Pay URLs and QR codes for point-of-sale and invoice flows. A request can carry the recipient, amount, token, reference, label, and message. These fields guide the wallet, but the chain remains the source of truth.
sequenceDiagram
participant Buyer
participant Merchant
participant Chain
participant Settlement
Buyer->>Merchant: Request or scan payment details
Merchant-->>Buyer: Solana Pay request with unique reference
Buyer->>Chain: Sign and submit SOL or token transfer
Chain-->>Settlement: Transaction becomes confirmed
Settlement->>Chain: Find reference and read transfer state
Settlement-->>Merchant: Fulfill only after recipient, mint, and amount match
For gasless payment flows, Kora can provide a trusted fee-payer or paymaster path. This changes who pays the network fee, not the need to show the user the transfer details or to verify settlement.
References: skills/…/payments.md• L14-21 skills/…/payments.md• L23-40
Payment user protection
Before signing, show the recipient, amount, token, fee payer, and target cluster. Use a memo or unique reference to correlate settlement, but keep retry and duplicate-payment control in the payment intent and order record.
Transaction status must match the user-visible action. Use confirmed for timely UI feedback and finalized when the service performs irreversible fulfillment. Treat a received signature as an intermediate result because the transaction can still fail or remain unconfirmed.
Transaction v1 is active on mainnet and is the default for new client code, but the connected wallet must support it. Check connected.supportedTransactionVersions.has(1) before sending and keep a version-0 path for wallets that do not. The fallback has the smaller 1232-byte transaction limit, so large proof or account sets may need a different transaction plan.
Settlement code must handle partial failure. When a transaction is sent without reaching the required commitment, it must rebroadcast the same signed transaction or reconcile chain state before re-signing. It must not trust a wallet callback as proof of payment, and fulfillment must be idempotent.
Readers and indexers must also opt in to v1 with the integer maxSupportedTransactionVersion: 1. For v1, compute and fee data lives in the message configuration rather than ComputeBudget instructions. Consumers must read that configuration and still handle legacy and v0 transactions.
References: skills/…/payments.md• L20-21 skills/…/payments.md• L29-32 skills/…/payments.md• L42-48 skills/…/transactions-v1.md• L8-12 skills/…/transactions-v1.md• L89-100 skills/…/transactions-v1.md• L135-161
System instructions
The System Program is the base instruction layer for SOL movement and account creation. A SOL payment uses a system transfer. Token account creation and other setup steps use system account creation with enough rent for the account's actual size.
Durable nonce accounts provide a longer-lived transaction lifetime for offline signing or delayed submission. They are useful when a value-moving transaction cannot be signed and sent within a normal recent-blockhash window.
References: skills/…/system.md• L6-12 skills/…/system.md• L18-36 skills/…/system.md• L51-83
Compute and inclusion
Compute budgeting controls how much execution capacity a transaction may use and how strongly it competes for block space. Legacy and v0 transactions express these settings with compute-budget instructions, while v1 stores them in the transaction message. Do not mix the two forms.
For v1, a plugin client can plan, simulate, and set resource limits when its transaction configuration selects version 1. A manual client must set or estimate both the compute-unit limit and loaded-account data limit because unset v1 limits are zero. The loaded-account limit needs headroom for accounts created between simulation and send.
The useful send sequence is:
- Choose a transaction version that the wallet, client libraries, and target cluster support.
- Build the value-moving instructions and set the version-specific resource limits. Add a priority fee when the network needs it.
- Simulate the transaction to estimate compute use. For v1, also estimate loaded account data size.
- Set limits with enough room for the measured work. In v1, unset resource limits are zero rather than runtime defaults.
- Refresh the recent blockhash after simulation.
- Sign, submit, and track confirmation.
For v1, the priority fee is a total lamport amount rather than a per-compute-unit price. Compute-budget instructions do not set v1 limits or fees. They consume an instruction slot and some compute instead, so remove them from v1 transactions. The v1 format raises the transaction size limit to 4096 bytes, which can help proof-heavy confidential flows, but the wallet and transport must support that version. Transactions larger than 1232 bytes must use base64 transport encoding.
Large account work or zero-knowledge proof work may need a larger heap frame. Most transfers do not. Priority fees should follow current network conditions rather than a fixed value.
References: skills/…/compute-budget.md• L14-22 skills/…/compute-budget.md• L30-47 skills/…/compute-budget.md• L50-61 skills/…/compute-budget.md• L104-153 skills/…/transactions-v1.md• L30-85 skills/…/transactions-v1.md• L228-350
Value-flow testing
Testing should move from fast instruction checks to realistic integration flows. LiteSVM or Mollusk can check token, payment, and compute behavior in process. Surfpool is the default integration environment for RPC flows, mainnet-fork state, complex CPIs, and transaction profiling. Its Kit plugin can provide the local RPC stack and typed cheatcodes inside the test process.
Use the test level that matches the risk:
- Unit level: Check account validation, authority rules, token balance changes, failure paths, and compute use with LiteSVM or Mollusk.
- Integration level: Check settlement, Token-2022 extensions, confidential-transfer context state, wallet-facing transaction assembly, and v1 resource configuration with embedded Surfpool.
- Cluster smoke level: Run a small devnet or target-cluster flow before release to confirm deployment and explorer-visible effects.
Keep integration suites serial when they share a surfnet. Use seeded accounts and exported snapshots when a payment or token state must be replayed in a stable way.
References: skills/…/SKILL.md• L70-74 skills/…/SKILL.md• L135-138 skills/…/testing.md• L20-30 skills/…/testing.md• L207-238 skills/…/testing.md• L353-380 skills/…/testing.md• L465-474
Security boundaries
Value-moving systems must assume that callers control every account and argument they pass. Programs therefore validate account ownership, signer status, writable status, PDA seeds, mint relationships, and the identity of every program used in a cross-program invocation (CPI).
The main security boundaries are:
- Authority: Require the expected signer and match it to stored ownership data.
- Asset identity: Validate the mint owner, token account, token program variant, decimals, and extension rules.
- Program identity: Do not accept an arbitrary CPI target or extra privileges for a callee.
- State lifecycle: Prevent reinitialization, duplicate mutable accounts, unsafe closure, and account revival.
- Arithmetic: Use checked math, safe narrowing conversions, and deliberate rounding direction.
- Ordering: Pin expected terms into the instruction and reload state after a CPI when the callee changed it.
Anchor's typed account constraints and typed CPI targets support these checks, but they do not replace product-specific rules. In Anchor v1, CPI construction identifies the called program by its program ID, so the program identity must remain explicit and known. Generated CPI account metas must also preserve signer status when a PDA signs.
A protocol must also account for unsolicited deposits. Raw token or lamport balances can include donations that did not pass through the protocol's accounting path. Independent internal counters keep those deposits from changing claims or exchange rates by surprise.
References: skills/…/security.md• L21-29 skills/…/security.md• L365-398 skills/…/security.md• L545-601 skills/…/security.md• L661-681 skills/…/anchor.md• L49-55 skills/…/anchor.md• L160-178 skills/…/migrating-v0.32-to-v1.md• L197-251 skills/…/anchor.md• L349-356
Client signing controls
Clients are part of the security boundary because they select the cluster, accounts, amounts, transaction version, and transaction instructions shown to the user. Use devnet or local simulation by default. Simulate before asking for a real signature and never handle private keys or seed phrases in application or agent flows.
RPC data is untrusted input. Validate account owner, data length, and discriminator before parsing it. Use trusted RPC infrastructure where possible because an observing or malicious RPC can delay or expose a transaction before it reaches a leader. Readers of transactions and blocks must opt in to v1 and read its message configuration rather than infer resource settings from compute-budget instructions. gRPC readers must classify v1 by the presence of message configuration before checking the older versioned flag, and stale protobuf stubs can silently drop that configuration.
References: skills/…/SKILL.md• L84-95 skills/…/security.md• L653-657 skills/…/security.md• L693-703 skills/…/transactions-v1.md• L135-221 skills/…/common-errors.md• L415-466
Change checklist
When these files or sections are changed, remember to consider these:
- When changing a mint's token program or extension set, update ATA derivation, account sizing, rent, transfer instruction choice, and downstream acceptance checks together.
- When changing payment references or memo fields, update settlement lookup, retry handling, and atomic duplicate-fulfillment protection as one contract. A reference or memo alone is not a duplicate-payment guard.
- When changing confidential-transfer cluster support, keep the endpoint configurable and update the pending-to-available user flow.
- When changing instructions that use simulation, refresh the blockhash after compute estimation before signing.
- When changing Token-2022 support, review transfer-fee deltas, permanent delegate trust, transfer hooks, memo rules, metadata links, close conditions, extension initialization order, and extension-aware account fetching.
- When enabling transaction v1, align wallet support checks, version-specific resource limits, base64 transport, transaction-size checks, and the version-0 fallback path.
- When reading or indexing v1 transactions, pass the integer version opt-in and read message configuration instead of scanning compute-budget instructions or using the generic
versionedflag alone. Regenerate protobuf schemas and pin the schema version when the reader uses gRPC. - When upgrading Anchor, keep
anchor-*crates and token interface dependencies on compatible versions, then recheck CPI target validation and PDA signer metas. - When changing test infrastructure, keep value-flow integration suites on a v1-capable local network and keep the unit-test and embedded-Surfpool paths aligned with production transaction assembly.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A Token-2022 ATA is derived with the base Token program identity | The client targets a different account or cannot find the user's funds | Derive the ATA with the mint's actual token program |
| Account space is fixed at classic Token sizes | Extension account creation fails or rent is misallocated | Calculate size and rent from the extension set |
| Extension instructions run after mint initialization | The extension setup cannot be applied to the finalized mint | Place pre-initialization extension setup before mint initialization and size the final account for later metadata or group data |
| A decoder trusts token data without checking the mint owner | Data from the wrong token program can pass parsing but fail or mislead later logic | Validate the account owner before decoding or accepting the asset |
| A protocol assumes the sent amount equals the received amount | Transfer-fee tokens break balances or allow over-withdrawal | Measure the balance delta or use an explicit checked fee |
| A payment service trusts a wallet callback | An unconfirmed or wrong transfer can trigger fulfillment | Find the unique reference and validate chain state at the required commitment |
| A payment timeout causes a new signature without reconciling the first transaction | The user can authorize two transfers for one order | Store the first signature, rebroadcast or reconcile it, and atomically claim fulfillment |
| A confidential transfer leaves funds pending | The recipient cannot spend the received value | Expose and complete the apply-pending step |
| Compute is estimated with an old blockhash | The signed transaction can expire before submission | Fetch a fresh blockhash after estimation |
| A v1 transaction leaves resource limits unset | Account loading or execution fails because the budget is zero | Estimate or set both v1 resource limits before signing |
| Compute-budget instructions are used to price a v1 transaction | The fee and limits remain unset while the extra instructions waste capacity | Put the budget in v1 message configuration |
| A v1 transaction larger than 1232 bytes uses base58 transport | Simulation or submission rejects the oversized encoding | Use base64 for large transactions |
| A reader does not opt in to transaction v1 | Transaction reads fail or block subscriptions stop at a v1 block | Pass maxSupportedTransactionVersion: 1 and support the v1 response shape |
An indexer checks versioned before message configuration | It classifies v1 as v0 and loses its resource and fee data | Check config presence first and use current protobuf schemas |
| A wallet cannot sign v1 but the client has no fallback | A valid payment cannot be signed by that user | Check supported versions and use a version-0 path |
| A program accepts an arbitrary CPI target | A malicious program can run with caller-provided privileges | Validate the target program ID and minimize privileges |
| A program infers protocol claims from raw balances | Donations can change accounting without a valid deposit | Track internal deposit and claim counters |
| A test uses a stale local network or mismatched Anchor/token crates | A value flow passes in tests but fails during build, simulation, or deployment | Use the compatible toolchain and a v1-capable integration environment |
Key files
| File | Why to read it |
|---|---|
| skills/…/tokens.md | Core token model, program ownership, ATAs, authorities, checked instructions, and Token-2022 extension behavior |
| skills/…/token.md | Core mint, token-account, ATA, checked-transfer, and user-flow guidance |
| skills/…/token-2022.md | Kit guidance for Token-2022 account sizing, ATA derivation, initialization order, and extension access |
| skills/…/confidential-transfers.md | Confidential balance states, operation lifecycle, availability, and key risks |
| skills/…/payments.md | Payment construction, Solana Pay requests, gasless options, retry behavior, and settlement rules |
| skills/…/system.md | SOL transfers, account creation, rent, and durable nonce concepts |
| skills/…/compute-budget.md | Simulation-led compute limits, priority fees, and transaction inclusion flow |
| skills/…/transactions-v1.md | Transaction v1 sending, wallet support, resource configuration, transport, and read-path changes |
| skills/…/security.md | Program, client, Token-2022, and value-accounting security review points |
| skills/…/anchor.md | Anchor account constraints, CPI safety, token interfaces, and current version guidance |
| skills/…/testing.md | Unit, integration, fork, and compute-profile paths for payment and token behavior |
| skills/…/compatibility-matrix.md | Supported Anchor, Solana SDK, client, wallet, and transaction v1 version combinations |
| skills/…/common-errors.md | Concrete transaction v1, wallet, RPC, and test-environment failure symptoms |