Solana Program Library (SPL) and Token Standards
11 min read
Welcome to module four of Basics of Solana Blockchain. In the Ethereum world, if you want to launch a token, you write and deploy an ERC-20 smart contract. If 50,000 developers launch tokens, Ethereum gets 50,000 copies of nearly identical smart contract bytecode consuming storage and demanding independent security audits.
Solana looked at that and said: “What if we deploy one rock-solid token program, and everyone just rents data accounts to store their balances?”
That single program is part of the Solana Program Library (SPL)—a collection of on-chain programs maintained by the core Solana ecosystem that provide standard building blocks for everyday operations.
1. Native SOL vs. SPL Token Fundamentals
📌 Definition & The Problem
- The Problem: Blockchains must handle two fundamentally different types of value: the native gas currency used by validators to pay for computational work, and custom assets (stablecoins, governance tokens, community points) created by users and protocols.
- The Definition:
- Native SOL is the protocol-level asset of the Solana blockchain.
- An SPL Token is an asset tracked by Solana's shared token programs (
Token ProgramorToken-2022).
⚙️ How Native SOL Works
In Solana’s architecture, accounts are data containers. Every account on Solana has a native field called lamports (where ).
When you send SOL to someone, the Solana runtime invokes the native System Program (11111111111111111111111111111111), which subtracts lamports from your account's balance and increments the recipient’s lamport balance. It requires zero custom smart contract execution.
🪙 How SPL Tokens Work
Unlike SOL, custom tokens (like USDC, BONK, or your own test token) are not recorded directly inside your primary wallet account.
Instead, Solana maintains a shared program: the SPL Token Program (TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA). When you hold an SPL token, the SPL Token Program creates a separate, specialized Token Account specifically to track your balance for that exact token.
+-------------------------------------------------------+
| User Wallet Account |
| Address: 7xKX... |
| Lamports: 2,500,000,000 (2.5 SOL) |
| Owner: System Program |
+-------------------------------------------------------+
|
Owns and is authorized to sign for
|
+--------------------------+----------------------------+
| |
v v
+-------------------------------+ +-------------------------------+
| Token Account (USDC) | | Token Account (BONK) |
| Address: 9aBC... | | Address: 3dEF... |
| Mint: EPjFWdd5... (USDC) | | Mint: DezXAZ8z... (BONK) |
| Balance: 50,000,000 ($50) | | Balance: 10,000,000,000 |
| Owner: 7xKX... (User) | | Owner: 7xKX... (User) |
| Program: SPL Token Program | | Program: SPL Token Program |
+-------------------------------+ +-------------------------------+🌯 Wrapped SOL (WSOL)
Because programs written for SPL tokens expect a Token Account rather than a raw lamport balance, standard protocols cannot process native SOL directly inside an SPL transfer instruction.
To solve this, Solana provides Wrapped SOL (WSOL) (Mint address: So11111111111111111111111111111111111111112). You deposit raw SOL into a Token Account owned by the Token Program, and the program treats it as a standard SPL token with 9 decimals.
🚧 Boundaries & Scope
| Feature | Native SOL | SPL Tokens |
|---|---|---|
| Transaction Fee Payment | ✅ Yes | ❌ No (validators only accept SOL for base fees) |
| Rent Exemption Payment | ✅ Yes | ❌ No (rent must be paid in SOL) |
| Custom Minting Logic | ❌ No (issuance is hard-coded in protocol inflation) | ✅ Yes (mint authority controls issuance) |
| Freezing/Transfer Hooks | ❌ No | ✅ Yes (configured per token mint) |
Why does this boundary exist? Validators must be rewarded in an asset that directly secures the consensus layer through Proof-of-Stake. If the runtime allowed gas fees in arbitrary SPL tokens, validators would take on foreign exchange volatility risks and liquidation overhead just to produce blocks.
2. Mints, Decimals, and Associated Token Accounts (ATAs)
📌 Definition & The Problem
- The Problem: If balances aren't stored in the main user wallet, how do programs prevent confusion about where tokens live? If Alice wants to send Bob some USDC, how does she know Bob’s USDC account address without asking Bob to generate and send an address string first?
- The Definition:
- Mint Account: A master ledger account that defines a token's identity, total supply, decimals, and management authorities.
- Associated Token Account (ATA): A deterministically derived token account tied directly to a specific user wallet and a specific mint.
🏭 The Anatomy of a Mint Account
A Mint Account does not store balances. It acts as the factory specification for a token. It holds exactly 82 bytes of data:
pub struct Mint {
pub mint_authority: COption<Pubkey>, // Address allowed to print new tokens
pub supply: u64, // Total quantity in circulation
pub decimals: u8, // Decimal places
pub is_initialized: bool, // Setup status
pub freeze_authority: COption<Pubkey>,// Address allowed to freeze token accounts
}Decimals: Human Readable vs. Machine Raw
Computers dislike floating-point math—rounding errors in DeFi turn into exploits. Like most blockchains, Solana represents all token balances as unsigned 64-bit integers (u64).
- If
decimals = 6(industry standard for USDC): Sending USDC means transferring1_500_000raw units. - If
decimals = 9(native SOL standard): Sending SOL means transferring100_000_000lamports.
📬 The Associated Token Account (ATA) Pattern
In early Solana days, users had to create arbitrary auxiliary token accounts. Alice could have three different USDC token accounts, and Bob had to guess which one to fund.
The Associated Token Account Program (ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL) fixed this by introducing a deterministic formula using Program Derived Addresses (PDAs).
An ATA address is derived off-chain or on-chain using three inputs:
Because this calculation uses a cryptographic hash (with a bump seed pushing it off the Ed25519 elliptic curve), there is only one valid ATA per mint, per wallet.
Alice wants to send Bob USDC:
1. Alice knows Bob's wallet address: "Bob111..."
2. Alice knows USDC Mint: "EPjFWd..."
3. Alice calculates: PDA(Bob111..., TokenProgram, EPjFWd...) = "BobUsdcATA..."
4. Alice sends tokens directly to "BobUsdcATA...".
(If it doesn't exist yet, Alice's transaction can initialize it for Bob first!)🚧 Boundaries & Scope
- Can one ATA hold multiple different tokens?
No. An ATA is linked to one, and only one, Mint address. If a user holds 20 different tokens, they will own 20 different ATAs. - Why this boundary exists:
Solana achieves high-speed parallelism (via the Sealevel runtime) by requiring transactions to declare which accounts they will read and write upfront. If an account held a balance sheet of all your tokens, every interaction with any of your tokens would lock your entire account, killing concurrent processing.
3. Minting, Transferring, and Freezing Tokens
Let's walk through the end-to-end lifecycle of an SPL Token using the official @solana/spl-token and @solana/web3.js libraries.
🛠️ Scenario: Launching "DevCoin" ($DVC)
We will:
- Initialize a new Mint.
- Derive and create an ATA for the receiver.
- Mint 1,000 $DVC into that ATA.
- Transfer 250 $DVC to a friend.
- Freeze the friend's account.
import {
Connection,
Keypair,
clusterApiUrl,
LAMPORTS_PER_SOL
} from "@solana/web3.js";
import {
createMint,
getOrCreateAssociatedTokenAccount,
mintTo,
transfer,
freezeAccount
} from "@solana/spl-token";
async function runTokenPipeline() {
// 1. Setup connection & payer
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
const payer = Keypair.generate();
const bob = Keypair.generate();
// Airdrop SOL to fund account creation and rent
const airdropSig = await connection.requestAirdrop(payer.publicKey, 2 * LAMPORTS_PER_SOL);
await connection.confirmTransaction(airdropSig);
console.log("Payer initialized:", payer.publicKey.toBase58());
// 2. Create the Mint Account
// Decimals = 2 (Like cents: 100 units = 1.00 DVC)
const mint = await createMint(
connection,
payer, // Fee payer
payer.publicKey, // Mint authority
payer.publicKey, // Freeze authority
2 // Decimals
);
console.log("Token Mint created:", mint.toBase58());
// 3. Create Associated Token Account for Payer
const payerAta = await getOrCreateAssociatedTokenAccount(
connection,
payer,
mint,
payer.publicKey
);
console.log("Payer ATA:", payerAta.address.toBase58());
// 4. Mint 1,000 DVC (with 2 decimals, this is 1,000 * 10^2 = 100,000 units)
await mintTo(
connection,
payer,
mint,
payerAta.address,
payer.publicKey, // Mint authority signer
1000 * 100
);
console.log("Minted 1,000.00 DVC to Payer");
// 5. Create Bob's ATA & Transfer 250 DVC
const bobAta = await getOrCreateAssociatedTokenAccount(
connection,
payer,
mint,
bob.publicKey
);
await transfer(
connection,
payer,
payerAta.address,
bobAta.address,
payer.publicKey, // Owner signer
250 * 100
);
console.log("Transferred 250.00 DVC to Bob:", bobAta.address.toBase58());
// 6. Freeze Bob's Account
// Because payer was designated as freezeAuthority, payer can halt Bob's account
await freezeAccount(
connection,
payer,
bobAta.address,
mint,
payer.publicKey // Freeze authority signer
);
console.log("Bob's ATA has been frozen 🧊");
}
runTokenPipeline().catch(console.error);🧊 What Freezing Actually Does (and Doesn't Do)
- What it does: Setting an account state to
Frozenblocks all incoming and outgoing transfer instructions for that specific token account. - What it does NOT do:
- It does not confiscate the tokens. The balance stays identical.
- It does not allow the freeze authority to extract the funds.
- It does not freeze the user's entire wallet—only that specific token account. Bob can still spend his SOL and other SPL tokens without hindrance.
💡 Tip: To revoke an authority forever (such as making a token unfreezable or capping total supply), set the respective authority to
null. This is a one-way street: once cleared, an authority can never be reclaimed.
4. Introduction to Token-2022 (Token Extensions)
📌 Definition & The Problem
- The Problem: The classic SPL Token Program was deployed in 2020. It is intentionally simple, immutable, and lean. However, modern financial applications require features like transfer fees (royalties/taxes), interest-bearing assets, privacy, and rich metadata. Previously, developers had to wrap tokens in complex custom smart contracts or rely on external protocols (like Metaplex) just to store a name and symbol.
- The Definition: Token-2022 (also called Token Extensions) is a brand-new token program deployed at
TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb. It retains standard token functionality while allowing developers to enable plug-and-play extensions directly at the mint or account level.
Classic Token Program Token-2022 (Extensions)
[TokenkegQfe...DA] [TokenzQdBN...Eb]
+--------------------------------+ +--------------------------------+
| Fixed 82-byte Mint Layout | | Base Mint + Extension TLV |
| | | [Type-Length-Value Slices] |
| - Supply | | - Supply |
| - Decimals | | - Transfer Fees (e.g., 2%) |
| - Mint Authority | | - Metadata (Name, Symbol) |
| - Freeze Authority | | - Transfer Hooks |
+--------------------------------+ +--------------------------------+🧩 Top Industry Token Extensions
Token-2022 structures extra data inside byte arrays using a TLV (Type-Length-Value) architecture, allowing specific extensions to be mixed and matched:
- Transfer Fees:
Configures a protocol-level fee (e.g., 1.5%) on every transfer that is automatically withheld into the recipient's token account. Only the fee authority can withdraw these withheld fees. - Transfer Hook:
Forces every transfer instruction to execute a secondary, custom Anchor/Rust program. This allows projects to implement custom KYC verification, on-chain allowlists, or programmatic royalties that cannot be bypassed. - Default Account State:
Requires newly created token accounts to be frozen by default until an external compliance check approves and thaws them. - Metadata & Metadata Pointer:
Embeds the token name, symbol, and URI directly inside the mint account data, cutting out the requirement to deploy a Metaplex metadata PDA account. - Non-Transferable ("Soulbound") Tokens:
Locks the token irrevocably to the initial recipient account, ideal for achievements, credentials, or non-tradable badges. - Confidential Transfers:
Uses ElGamal encryption and zero-knowledge proofs (ZK-SNARKs/Twisted ElGamal) so that token balances and transfer amounts remain private while remaining auditable on-chain.
⚠️ Token-2022 Boundaries & Ecosystem Gotchas
Token-2022 is the technical standard for new tokens on Solana, but it introduces architectural nuances:
- Account Sizing & Rent: A classic Mint costs a fixed in rent exemption. A Token-2022 mint with multiple extensions is physically larger in bytes, demanding more rent.
- Compatibility Gotchas: A legacy decentralized exchange (DEX) written to interact strictly with
Tokenkeg...will fail if a user tries to trade aTokenz...token unless the DEX has updated its instruction processors to accept the new Program ID. - Transfer Hooks Consume Compute Units: When a transfer calls a secondary hook program, your transaction's compute budget must accommodate both the token transfer and the hook logic.
🧠 Check Your Understanding
- Why does your wallet have a different address for holding USDC than its primary address?
- Answer: Your primary address is a System Program account that holds native SOL. USDC is held in a distinct Associated Token Account (ATA) owned by the SPL Token Program, derived from your wallet address and the USDC mint address.
- Can you update a token's decimal value after creating the Mint Account?
- Answer: No. The decimal layout is fixed at initialization to ensure mathematical determinism for on-chain protocols.
- If you freeze an account, does the token balance disappear?
- Answer: No. The account state changes from
InitializedtoFrozen. Balances stay intact, but any instructions attempting to modify that balance fail until an authorized signature runsthawAccount.
- Answer: No. The account state changes from
📚 References & Further Reading
Challenge
As a blockchain developer working on a Solana project, you are tasked with evaluating the adoption of Token-2022 versus the legacy SPL Token Program. Below are three practical scenarios requiring you to fill in the blanks with technical terms or concepts derived from the summary.
Account Derivation: To ensure a wallet only has one canonical token account for a specific mint, Solana relies on deterministically derived addresses. This process uses Program Derived Addresses (PDAs) incorporating the wallet address, the token program ID, and a seed known as the _________ seed. This mechanism eliminates guessing when constructing addresses for token operations.
Token-2022 Extension Impact: When migrating to Token-2022, while extensions like transfer hooks offer powerful features (like KYC or royalties), they inherently increase the overall size and associated _________ costs compared to standard SPL tokens. Furthermore, adopting Token-2022 can potentially break older decentralized exchanges (DEXs) that are only configured to recognize the older Token Program ID due to increased required account _________.
Cost Management: A key industry takeaway regarding token architecture is understanding the difference between the native SOL management and SPL token management. Only native SOL is exempt from transaction fees and rent costs managed by the System Program. SPL tokens, being tracked by the Token Program, require users to pay their own _________ for transaction execution, even if the token itself has a zero market value.
Expected result
Provide the three required terms that complete the technical sentences above. The response must accurately reflect the technical details regarding PDA seeds, the financial and compatibility trade-offs of Token-2022, and the specific fee structure of SPL tokens.