SPL tokens can represent various assets, including cryptocurrencies, stablecoins, NFTs, and even tokenized real-world assets like commodities or real estate. They enable transfers, exchanges, staking, lending, and a variety of financial operations.
Fungible Tokens: These tokens are interchangeable with one another. They are indistinguishable and hold the same value.
Non-Fungible Tokens (NFTs): Each NFT is a special digital asset that holds a unique information or value. NFTs can represent ownership of a specific digital or physical item, such as digital art or real estate.
Token program defines a common implementation for fungible and non-fungible tokens. All tokens on Solana are created using the SPL Token program. It supports functions like minting, transferring, freezing, burning, and more.
Tokens on Solana are uniquely identified by the address of a mint account owned by the Token Program. Mint accounts store global metadata of tokens.
Fields of a mint account:
- Supply: Total supply of the token.
- Decimals: The number of decimal places the token can be divided into.
- Mint authority: The account authorized to mint new tokens. (Optional)
- Freeze authority: The account authorized to freeze token transfers. (Optional)
This is what the mint account of USDC looks like.
A Token Account on Solana is a type of account that holds a balance of a specific token for a user. Each token account is tied to one type of token, meaning you need a separate token account for each different type of token you want to hold.
Main fields:
- Mint: The type of token the account holds.
- Owner: The account with authority to transfer the tokens.
- Amount: The number of tokens the account holds.
Additional fields:
- Delegate: Delegate authority having possession over delegate amount. (Optional)
- IsNative: Specifies whether the token account holds wrapped SOL. (Optional)
- Delegate amount: Amount authorized by the delegate authority.
- Close authority: Authority able to close the token account. (Optional)
An Associated Token Account (ATA) is a token account that has its address derived (as a PDA) from its owner's wallet address and the address of the mint. Each user has a unique ATA for each combination of wallet and token mint, which is convenient because programs can derive the address and interact with the token account without needing the actual address to be provided.
Note
A user can receive tokens even if they do not yet have a token account for that mint. The sender is able to fund the creation of the receiver's ATA, enabling things like airdrop campaigns.
Tip
You can try these examples out on localnet by running:
solana-test-validator
Use the spl-token CLI to create a new SPL token and establish its mint account.
spl-token create-token
Check its supply.
spl-token supply <TOKEN_ADDRESS>
By default the create-account command creates an associated token account with your wallet address as the token account owner. Use optional --owner
flag to create a token account with a different owner.
spl-token create-account --owner <OWNER_ADDRESS> <TOKEN_ADDRESS>
Mint tokens to a specified token account.
spl-token mint <TOKEN_ADDRESS> <AMOUNT> <RECIPIENT_ADDRESS>
Transfer tokens from one token account to another.
spl-token transfer <TOKEN_ADDRESS> <AMOUNT> <RECIPIENT_TOKEN_ACCOUNT>
If you have any questions feel free to reach out to us on Discord.