Hello! Welcome to the first lesson of our module on working with Solana tokens.
Over the past few modules, you've built a solid foundation in Rust and the core mechanics of Solana development, including how to structure programs, manage accounts, and even perform Cross-Program Invocations (CPIs). Now, we're going to apply that knowledge to one of the most fundamental parts of any blockchain ecosystem: tokens.
In this lesson, we will focus on understanding the architecture of the Solana Program Library (SPL) Token program. You will learn to describe its key components, specifically mints and token accounts. This conceptual framework is essential for the upcoming lessons, where you'll start writing code to create, mint, and transfer your own tokens.
The SPL Token Standard: A Different Paradigm
If you have any familiarity with Ethereum, you might know of standards like ERC-20, where each new token is its own separate smart contract. Solana takes a different, more efficient approach that builds directly on its core account model.
To get a high-level overview of this paradigm, please read the first few sections of the following article. It does an excellent job of contrasting the Solana and Ethereum models and introducing the core components we'll be discussing.
This article from rareskills.io, 'How the SPL Token Works', introduces the fundamental concepts of Solana's token standard.
Please read from the beginning of the article down to the end of the 'Token Program' section. Focus on understanding why Solana uses a single program for all tokens and how this separates logic from state.
As the article highlights, the key takeaway is this: on Solana, there isn't a new program for every token. Instead, there is one primary program—the SPL Token Program—that contains all the logic for every token. The unique characteristics of each token (like its name, supply, etc.) are stored in separate data accounts.
This design has two main programs you'll encounter:
- Token Program: The original, battle-tested program for creating fungible and non-fungible tokens (NFTs). Its address is
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA. - Token-2022 (Token Extensions): A newer version that includes all the original features plus new "extensions" for more advanced functionality like transfer fees, confidential transfers, and more.
For most of this course, we will interact with the original Token Program, as its principles are foundational to the entire ecosystem.
The Mint Account: The Token's Blueprint
So, if the program logic is shared, how does Solana define a specific token like USDC or your own future "MyCoolToken"? This is the role of the Mint Account.
A Mint Account is a unique data account that serves as the single source of truth for one specific token type. It doesn't hold any user's balance; instead, it stores the global metadata about the token.
The core properties of a Mint Account are:
supply: The total number of tokens that have been created (minted).decimals: The number of decimal places the token uses. This is crucial for UI representation. For example, USDC has 6 decimals, meaning au64value of1,000,000in a token account represents1.0USDC.mint_authority: An optional public key of the account that is allowed to create, or "mint," new tokens, thereby increasing thesupply. If this authority is set toNone(a null value), the token supply becomes fixed forever.freeze_authority: An optional public key that can "freeze" any token account holding this token, preventing tokens from being transferred.
Let's dive deeper into the structure and purpose of the Mint Account.
The 'How the SPL Token Works' article provides a detailed explanation of the Mint account.
Please read the 'Mint account' section. Pay close attention to the role of each data field and the mechanism for creating a fixed-supply token by disabling the mint_authority.
From your developer perspective, it's helpful to see what this looks like in code. The official Solana documentation shows the Rust struct that defines the state of a Mint Account.
The official Solana documentation on tokens provides the Rust struct definition for a Mint account.
Review the 'Mint Account' section, especially the pub struct Mint code block. This shows you the exact data structure that gets stored on-chain.
This short video clip provides a good verbal summary of how token mints, supply, and decimals work in practice.
How to Create a Solana SPL Token
This clip from a Solana channel video explains the concepts of token mints and decimals.
Watch this brief segment to reinforce your understanding of how token amounts are represented as integers (u64) and how decimals are used for display purposes.
Token Accounts: Where Users Hold Their Balances
We've established that the Mint Account defines the token. But where do users actually store their tokens? They can't be in the Mint Account, and they can't be in a user's main wallet account, which can only hold SOL.
This is where Token Accounts come in. A Token Account is another data account that holds a balance of one specific token for one specific owner.
Each Token Account contains:
mint: The address of the Mint Account this token account is associated with.owner: The address of the user (or program) that has the authority to sign for transfers out of this account.amount: Theu64quantity of the token held in this account.
This diagram from the Solana documentation illustrates the relationship: a user's wallet is the 'owner' of a Token Account, which holds a balance of a specific token 'mint'. The Token Account itself is owned by the SPL Token Program.
Initially, this design presented a usability challenge: a user could create multiple Token Accounts for the same mint. If you wanted to send someone USDC, how would you know which of their many USDC token accounts to send it to?
The solution is a special, standardized type of token account: the Associated Token Account (ATA).
An ATA is simply a Token Account whose address is deterministically derived from two seeds:
- The user's main wallet address.
- The token's Mint Account address.
This should sound very familiar! ATAs are Program Derived Addresses (PDAs). Because the address is predictable, anyone can figure out the correct token account address for any user and any token without having to ask. This has become the universal standard for managing tokens on Solana.
The following resources explain this relationship in detail.
How to Create a Solana SPL Token
This clip explains the need for a separate token account to hold tokens, distinguishing it from the token mint.
Watch this segment to understand the fundamental difference between a mint (metadata) and a token account (a holder of the balance).
Now, let's read the definitive explanation of Token Accounts and Associated Token Accounts (ATAs).
Please read the sections 'Token Accounts and Associated Token Accounts (ATAs)', 'Associated Token Account Program', and the 'Summary'. Focus on: The problem that ATAs solve. How an ATA's address is derived (connecting to your knowledge of PDAs). The role of the Associated Token Account Program as a helper.
Test your understanding!
Imagine you are building a dApp. A user, Alice, wants to send 10 USDC to another user, Bob. Neither Alice nor Bob have ever used USDC before on your dApp.
Based on the architecture you've just learned about, describe the key accounts and programs that would be involved in the transaction that sends the tokens. What information is needed to find or create Bob's receiving account?
Show answer
Here are the key components involved:
- Bob's Wallet Address (
Bob_PubKey): This is the primary piece of information needed. - USDC Mint Address (
USDC_Mint_PubKey): This is the public address of the USDC Mint Account. - Bob's Associated Token Account (ATA) for USDC: Before Alice can send the tokens, this account must exist. Its address is a PDA derived from
Bob_PubKeyandUSDC_Mint_PubKey. The transaction Alice sends will likely include an instruction to create this account if it doesn't already exist. - Alice's Associated Token Account (ATA) for USDC: This is the source account, which must already exist and contain at least 10 USDC.
- Alice's Wallet Address (
Alice_PubKey): Alice must sign the transaction to authorize the transfer from her ATA. - SPL Token Program: This program will process the
transferinstruction, debiting Alice's ATA and crediting Bob's ATA. - Associated Token Account Program: This program is often used to process the
createinstruction for Bob's ATA, which in turn makes a CPI to the System Program (to create the account) and the SPL Token Program (to initialize it as a token account).
In short, Alice's wallet needs Bob's public key and the USDC mint address to deterministically calculate the address of Bob's ATA, create it if necessary, and then transfer the tokens to it.
Conclusion
You've now covered the core architecture of the SPL Token standard, which is fundamental to building almost any application on Solana. Let's recap the key takeaways:
- Centralized Logic, Decentralized State: Solana uses a single SPL Token Program that contains the rules for all tokens. The state (like supply and balances) is stored in separate data accounts.
- Mint Account as Blueprint: A Mint Account is a data account that uniquely defines a token. It stores the global supply, decimals, and mint/freeze authorities. The mint address is the token's address.
- Token Accounts as Wallets: A Token Account holds a user's balance for a single token type.
- ATAs as the Standard: The Associated Token Account (ATA) is the standard implementation of a token account. It's a PDA whose address is derived from a user's wallet address and the token's mint address, making it predictably discoverable.
In our next lesson, we will move from theory to practice. You will write Anchor code to perform a Cross-Program Invocation (CPI) to the SPL Token Program to create your very first Mint Account, putting the concepts from today into action.
Can't find a good explanation? Sign up and we'll make it for you
Sign up