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 / core-token-operations

Core token minting and transfer operations

The core token examples show how a Solana program creates a standard token, issues balances, and transfers those balances. They also show two authority designs: a program-derived address (PDA) can control minting, and an external signer can add proof to a program-managed transfer.

Token lifecycle

Mint creation

The mint is the shared definition of an asset. Creation sets its decimal precision and initial mint authority, then adds a metadata record that gives the asset a name, symbol, and URI. A fungible token uses decimal places such as nine. An NFT uses zero decimals and is later issued as one unit.

The examples expose this flow through native and Pinocchio program variants. They use the standard token program and the Token Metadata program together. The payer funds the new accounts, while the chosen authority controls later supply changes. The native and Pinocchio variants use the same instruction data shape for the metadata strings and decimal count.

flowchart LR
    A[Choose decimals and authority] --> B[Create mint]
    B --> C[Create metadata]
    C --> D[Mint can hold balances]

References: tokens/…/lib.rs• L17-39 tokens/…/lib.rs• L41-98 tokens/…/create_token.rs• L15-35 tokens/…/create_token.rs• L38-98 tokens/…/processor.rs• L6-21 tokens/…/util.rs• L3-16

Balance minting

Minting increases the supply of an asset and places the new balance in a token account for a chosen owner. The examples use the owner's associated token account and create it as part of the mint flow when needed.

Amounts are expressed in the mint's smallest units. The standard token flow accepts a raw quantity. The PDA authority flow issues one unit for an NFT, then creates a master edition that prevents further supply through the normal mint path.

References: tokens/…/mint_spl.rs• L11-65 tokens/…/mint_nft.rs• L10-60 tokens/…/mint.rs• L32-68 tokens/…/mint.rs• L20-80

Balance transfer

Transfer moves an existing balance between token accounts for the same mint. It reduces the source balance and increases the destination balance without changing total supply. The source owner signs the debit; the recipient is named as the destination owner and does not approve receipt.

The examples also support first receipt. If the recipient's associated token account does not exist, the payer creates it before the token program moves the balance. This keeps recipient setup inside the transfer flow. The client encodes the quantity as an unsigned 64-bit value that matches the native program's instruction data.

sequenceDiagram
    participant Owner
    participant Client
    participant Program
    participant Token as Token program
    participant Recipient

    Owner->>Client: Choose mint, recipient, and amount
    Client->>Program: Submit owner and payer signatures
    Program->>Program: Create recipient account if needed
    Program->>Token: Authorize source debit
    Token->>Token: Move existing balance
    Token-->>Recipient: Update destination balance

References: tokens/…/transfer.rs• L11-29 tokens/…/transfer.rs• L29-47 tokens/…/transfer.rs• L53-76 tokens/…/transfer.ts• L13-17 tokens/…/transfer.ts• L19-45 tokens/…/transfer.rs• L8-47 tokens/…/processor.rs• L15-31

PDA mint authority

A PDA mint authority lets a program control supply without giving mint authority to a normal wallet. The PDA is a deterministic address derived from the program and seed data. The program can use that address to sign its call to the token program.

The native flow initializes a PDA account, stores its bump, and checks the derived PDA before it creates a mint or issues an NFT. The Pinocchio flow also checks the canonical PDA and stored bump before it creates a mint. The Anchor flow stores an admin relationship and accepts a mint request only from that admin. These checks keep the PDA signing path tied to the intended mint authority.

flowchart TD
    A[Initialize mint authority PDA] --> B[Create mint with PDA authority]
    C[Caller requests mint] --> D{Authority checks pass?}
    D -- No --> E[Reject request]
    D -- Yes --> F[Program signs as mint PDA]
    F --> G[Token program increases supply]

References: tokens/…/init.rs• L14-40 tokens/…/create.rs• L23-37 tokens/…/mint.rs• L13-30 tokens/…/init.rs• L12-37 tokens/…/create.rs• L21-59 tokens/…/create.rs• L61-97 tokens/…/mint.rs• L39-76 tokens/…/test.ts• L127-177 tokens/…/create.rs• L14-56 tokens/…/mint.rs• L10-70

External delegate transfers

The external delegate example adds an external wallet signature to a program-level token transfer. A user record links a Solana authority to an external address, while a PDA controls the user's token account. The program accepts the transfer only after it validates both the Solana authority and the external signature.

The signed data binds the program, user record, source, destination, amount, and current nonce. The program checks that the recovered external address matches the stored address, then advances the nonce and authorizes the token transfer through the PDA. The external signer adds proof of intent; it does not replace the Solana authority.

This pattern is separate from the token account's built-in delegate field. The example also provides an authority-only path that uses the same PDA-controlled account without an external signature.

sequenceDiagram
    participant External as External signer
    participant Authority as Solana authority
    participant Program as Delegate program
    participant Token as Token program

    External->>External: Sign nonce-bound transfer data
    Authority->>Program: Submit transfer and signature
    Program->>Program: Recover address and validate data
    Program->>Program: Advance nonce
    Program->>Token: Sign as user PDA
    Token-->>Authority: Move balance

The client and program must build the same raw digest. The example does not add a personal-sign prefix. Replay attempts, changed transfer data, and unregistered external keys are rejected.

References: tokens/…/lib.rs• L13-85 tokens/…/lib.rs• L104-195 tokens/…/litesvm.test.ts• L22-71 tokens/…/litesvm.test.ts• L163-325

These operations provide the base mint and balance model for more specialized systems. The token program examples place these flows in the wider token example set. Token-2022 extensions add mint and account rules around transfers. NFT and Merkle token flows build issuance and claim paths on the same model. Token exchange and fundraising use transfers to move assets through escrow, pools, or contribution accounts.

Change checklist

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

  • Keep the mint authority selected at creation aligned with every mint path.
  • Keep PDA seeds, stored bumps, and signer inputs aligned between authority setup and every PDA-signed operation.
  • Keep the stored admin record tied to the same PDA-controlled mint.
  • Keep source and destination token accounts tied to the same mint. Keep recipient and payer roles separate.
  • Keep the external digest format identical in the client and program. Check domain, account order, amount encoding, nonce, and prefix rules.
  • Advance the external nonce only for an accepted transfer.
  • Keep amount units consistent. Native quantities use the mint's smallest units.
  • Keep the create-token string encoding and field order identical between native clients and Pinocchio processing.

Important failure modes

TriggerConsequenceGuard
Caller is not the configured mint adminPDA mint request is rejectedCompare the caller with the stored admin record
PDA account has an invalid or missing bumpPDA-signed creation or minting failsStore the canonical bump during initialization and derive the same PDA later
Mint authority does not match the signer pathToken program rejects the supply increaseUse the authority selected when the mint was created
Create-token data uses a different string layout or is truncatedThe instruction is rejected or the fields cannot be readUse the shared Borsh string layout and field order
Recipient account is missing and the payer cannot fund itTransfer fails before balances changeProvide a valid payer and associated-token account path
Recipient is required to sign a normal transferThe transfer can fail even though receipt needs no approvalMark the recipient as read-only
Source and destination use different mints or the source lacks balanceToken program rejects the transferDerive both accounts from one mint and keep enough source balance
External signature uses changed data or an old nonceTransfer is rejectedVerify one exact digest and use the current nonce
External signer is not registeredTransfer is rejectedRecover the address and compare it with the user record
Client sends the wrong amount unitRecipient receives too much or too littleConvert to smallest units before submission

Key files

FileWhy to read it
tokens/…/lib.rsShows standard mint creation and metadata attachment.
tokens/…/create_token.rsShows the matching mint-creation flow and shared instruction data shape in the Pinocchio example.
tokens/…/processor.rsShows how the Pinocchio entry point routes the create-token payload.
tokens/…/mint_spl.rsShows fungible balance issuance and first associated-account setup.
tokens/…/mint_nft.rsShows one-unit NFT issuance and master-edition creation.
tokens/…/transfer.rsShows first receipt account creation and source-owner authorization.
tokens/…/transfer.tsShows the client account roles and quantity encoding for transfers.
tokens/…/transfer.rsShows the same recipient setup and transfer flow in the Pinocchio example.
tokens/…/init.rsShows creation of the program-owned mint-authority PDA.
tokens/…/mint.rsShows PDA signing for NFT issuance and edition creation.
tokens/…/init.rsShows canonical PDA validation and persisted bump setup.
tokens/…/create.rsShows PDA validation and signing while creating the NFT mint and metadata.
tokens/…/test.tsShows PDA setup, NFT creation, and master-edition verification.
tokens/…/mint.rsShows PDA validation and signing in the Pinocchio example.
tokens/…/lib.rsShows external signature validation, nonce use, PDA signing, and the authority-only path.
tokens/…/litesvm.test.tsShows the accepted external-signature flow and its main rejection cases.