DEV Community

Cover image for Building an SPL Token on Solana: Minting Tokens and Understanding ATAs
Ladipo Samuel
Ladipo Samuel

Posted on

Building an SPL Token on Solana: Minting Tokens and Understanding ATAs

So far, our token has a Mint and metadata, but technically, nobody owns any of it yet. We haven't minted a single token, which means the supply is still zero.
The next step seems obvious: mint some tokens. But while doing this, I ran into another question that helped me understand Solana better: when tokens are minted, where exactly do they go?
Your tokens don't actually sit in your wallet
At first, it's easy to think of a wallet as one account containing everything you own. On Solana, SPL tokens work a little differently. Your wallet controls them, but the balances themselves live in separate Token Accounts.

If I own three different tokens, I can picture it like this:

My Wallet
│
├── Token Account for Token A → 50
├── Token Account for Token B → 100
└── Token Account for Token C → 20
Enter fullscreen mode Exit fullscreen mode

Each Token Account is for one specific Mint. This means the account holding my balance of Token A isn't the same account holding my balance of Token B.
This is where Associated Token Accounts, or ATAs, come in.

Understanding the ATA
An ATA is the standard Token Account for a specific wallet and Mint combination.
I find it easier to think of it as answering this question:

Where should this wallet's balance of this particular token live?

Given the wallet and Mint, we can deterministically derive its ATA, meaning the same wallet and Mint will always lead us to the same ATA address.

Wallet + Mint
     ↓
    ATA
     ↓
Balance of that token
Enter fullscreen mode Exit fullscreen mode

So my wallet can have one ATA for the token we're building, while another wallet will have a different ATA for the exact same token.
In the code, we derive ours like this:

const [ata] = await findAssociatedTokenPda({
mint,
owner: signer.address,
tokenProgram: TOKEN_PROGRAM_ADDRESS,
});

Something from the architecture article shows up again here: finding an address doesn't necessarily mean an account exists there yet. We know where our ATA should be, but if it hasn't been created on-chain, we still need to create it.
Once that account exists, we finally have somewhere to send our tokens.

Now we can actually mint

Minting means creating new units of our token and sending them to a Token Account.
So underneath the SDK functions, what we're really asking the Token Program to do is:

Our Mint
   │
   │ create new token units
   ▼
Our ATA
Enter fullscreen mode Exit fullscreen mode

But we can't just mint tokens whenever we want. When we initialized the Mint earlier, we assigned a mint authority. That authority is what gives our wallet permission to create new units of the token. Knowing the Mint address alone isn't enough to increase its supply.
Decimals matter here too. Our Mint uses 6 decimals, so:

1 token = 1,000,000 base units
100 tokens = 100,000,000 base units
Enter fullscreen mode Exit fullscreen mode

What actually changed?
This is probably the simplest way to see what minting did. Once the ATA has been created, but before minting:

Mint Account
Supply: 0

ATA
Balance: 0
Enter fullscreen mode Exit fullscreen mode

We mint 100 tokens into our ATA:

Mint Account
Supply: 100
      │
      │ mint
      ▼
ATA
Balance: 100

Enter fullscreen mode Exit fullscreen mode

Two pieces of state changed. The Mint's total supply increased because 100 new tokens now exist, and our ATA's balance increased because that's where those tokens were sent.
That distinction ties everything together for me where the Mint keeps track of the token itself and its overall supply, while Token Accounts keep track of who holds how much.

Where we are now
We've gradually moved from defining a token to actually having tokens that can be used:

Create Mint
     ↓
Add Metadata
     ↓
Derive/Create ATA
     ↓
Mint Tokens
     ↓
Our ATA now holds them
Enter fullscreen mode Exit fullscreen mode

At this point, we finally have actual token units sitting in an account controlled by our wallet.
But tokens become more interesting when they can move. So the next question is: if I want to send some of these tokens to another wallet, what exactly happens to my ATA, their ATA and the Mint's total supply?
That's where we'll pick up with SPL token transfers.

Top comments (0)