SPL Token Basics
9 examples to get you started with SPL Token - 7 basic and 2 intermediate.
Prerequisites
solana config set --url devnet
solana airdrop 2
spl-token --versioncargo add anchor-lang@0.32.1 anchor-spl@0.32.1
npm install @solana/kit@7.0.0SPL Token program ID: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA.
Basic Examples
1. Create a Mint
A mint account defines decimals, supply, and authorities.
spl-token create-token --decimals 6decimalssets how raw amounts map to human-readable values- Mint authority can mint more until revoked
- Freeze authority is optional;
Nonemeans accounts cannot be frozen
Related: Minting & Burning - supply changes
2. Inspect Mint State
Read supply and authority fields before integrating clients.
spl-token display <MINT>Supplyis raw integer units (not UI amount)Mint authoritypubkey controls inflationFreeze authorityofdisabledmeans no freeze capability
Related: Authorities - revoke patterns
3. Create a Token Account (ATA)
Wallets hold balances in token accounts, not the mint itself.
spl-token create-account <MINT>- Associated Token Account (ATA) address is a PDA from wallet + mint
- One ATA per wallet per mint is the standard UX pattern
- Account size is 165 bytes (~2M lamports rent-exempt)
Related: Associated Token Accounts (ATAs)
4. Mint Tokens to an ATA
Increase supply by crediting a token account.
spl-token mint <MINT> 10000001000000raw units = 1.0 token when decimals = 6- Requires signer to hold mint authority
- Supply updates on the mint account atomically
Related: Decimals & Amounts
5. Transfer Between Token Accounts
Move balances without changing total supply.
spl-token transfer <MINT> 500000 <RECIPIENT_WALLET> --fund-recipient- Source must be your ATA for that mint
--fund-recipientcreates recipient ATA if missing- Delegates can transfer on behalf of owner when approved
Related: Transfers & Delegates
6. Read Balances with @solana/kit
Clients query token accounts over standard RPC.
import { createSolanaRpc, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.devnet.solana.com");
const owner = address("YOUR_WALLET");
const { value } = await rpc
.getTokenAccountsByOwner(owner, { mint: address("MINT_PUBKEY") }, { encoding: "jsonParsed" })
.send();
const balance = value[0]?.account.data.parsed.info.tokenAmount.uiAmount;
console.log("Balance:", balance);jsonParsedreturns UI amount and raw amount together- Empty array means no ATA exists yet for that mint
- Use DAS for NFT metadata; use token RPC for fungible balances
Related: Wrapped SOL - native SOL as SPL
7. Burn to Reduce Supply
Permanently remove tokens from circulation.
spl-token burn <MINT> 100000- Burns from your ATA balance, not from arbitrary holders
- Decreases mint supply field
- Common before revoking mint authority for fixed-supply tokens
Related: Minting & Burning
Intermediate Examples
8. CPI Transfer in an Anchor Program
Programs move tokens via cross-program invocation (CPI).
use anchor_lang::prelude::*;
use anchor_spl::token::{self, Token, TokenAccount, Transfer};
#[derive(Accounts)]
pub struct PayFee<'info> {
#[account(mut)]
pub user_token: Account<'info, TokenAccount>,
#[account(mut)]
pub treasury_token: Account<'info, TokenAccount>,
pub authority: Signer<'info>,
pub token_program: Program<'info, Token>,
}
pub fn pay_fee(ctx: Context<PayFee>, amount: u64) -> Result<()> {
let cpi = CpiContext::new(
ctx.accounts.token_program.to_account_info(),
Transfer {
from: ctx.accounts.user_token.to_account_info(),
to: ctx.accounts.treasury_token.to_account_info(),
authority: ctx.accounts.authority.to_account_info(),
},
);
token::transfer(cpi, amount)?;
Ok(())
}Account<'info, TokenAccount>deserializes SPL layout and validates owner- Signer must be token account owner or approved delegate
- Always validate mint matches across from/to accounts in production
Related: SPL Token in Programs
9. Revoke Mint Authority (Fixed Supply)
Lock supply after initial distribution.
spl-token authorize <MINT> mint --disable- Irreversible on that mint - no more inflation possible
- Standard launch pattern: mint allocation, airdrop, then revoke
- Document authority changes for transparency and indexers
Related: SPL Token Best Practices - launch checklist
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.