Back to Videos

SPL Token Program Library: How to use it & why?

Wednesday, May 28, 2025

Neon Dev Bootcamp – Week 4: SPL Token Program Library: How to use it & why?

Lesson Overview

Welcome to Week 4 of the Neon Dev Bootcamp!

In this tutorial, you’ll learn how to use Neon EVM's composability libraries to create and interact with an SPL token on Solana using Solidity. By the end, you’ll be able to:

  • Initialize a new SPL token mint from a Solidity contract
  • Create associated token accounts (ATAs)
  • Mint, transfer, and burn tokens
  • Understand how ATAs differ from arbitrary token accounts
  • Use getter functions to read SPL token data

Token Models: Ethereum vs Solana

Ethereum Tokens (ERC-20)

  • Tokens are smart contracts.
  • One contract = one token.
  • Balances stored in mappings like mapping(address => uint256).
  • Methods like transfer() and approve() modify balances.

Solana Tokens (SPL)

  • Tokens are managed by a central SPL Token Program.
  • User balances are stored in separate token accounts.
  • Token accounts must be explicitly created.
  • Solana uses Mint Accounts for metadata and Token Accounts for balances.
  • Interactions require explicit authority management.

Feature Ethereum Solana
Token Representation Smart contracts Program + data accounts
Balance Location Contract state Token accounts
Token Creation Implicit Must create accounts explicitly
Standards ERC-20, ERC-721, etc. SPL
Multi-token support per address Yes No
Approvals approve() method Per token account delegation
Authority Contract-controlled Token-specific authorities

Key Solana Concepts

Mint Account

Stores metadata like:

  • Total supply
  • Decimal precision
  • Mint authority
  • Freeze authority

Token Account

Holds tokens for a specific owner and mint:

  • mint: token type
  • owner: account owner
  • amount: token balance

Associated Token Account (ATA)

  • Deterministically derived from owner + mint.
  • Acts as the default token account.
  • Created using Program Derived Addresses (PDAs).

Arbitrary Token Account

  • Manually created token accounts.
  • Useful for advanced setups (e.g., multiple delegates).

How It All Connects

  1. Use the System Program to create an account (via Neon libraries).
  2. Use the SPL Token Program to initialize it as a token account or mint.

Neon EVM wraps this with composability libraries:

Libraries

  • SPL Token Program Library: handles minting, transfers, and account actions.
  • Associated Token Program Library: manages ATAs.
  • Data Helpers: retrieves on-chain data in Solidity.

SPL Token Program Library in Action

1. Create & Initialize a Mint

initializeToken();
formatInitializeMintInstruction();

2. Create Token Accounts

initializeArbitraryTokenAccount();
formatCreateAccountWithSeedInstruction();
formatInitializeAccountInstruction();
formatCreateAssociatedTokenAccountInstruction();

  • ATA: one per user per token
  • Arbitrary Token Account: custom use cases

3. Mint & Transfer Tokens

mint();
formatMintToInstruction();
transfer();
formatTransferInstruction();

4. Approvals & Claims

burn();
revokeApproval();
closeTokenAccount();

Getter Functions

  • getTokenSupply()
  • getMintAuthority()
  • getDecimals()
  • getBalance()
  • getDelegate()
  • getAssociatedTokenAccount(owner, mint)
  • getArbitraryTokenAccount(owner, mint, nonce)
  • getFullAccountData()

CallSPLTokenProgram.sol

This Solidity contract acts as a bridge to Solana’s SPL Token Program using Neon’s composability features.

Key Functions

  • createInitializeTokenMint()
    • Creates mint account with CALL_SOLANA.createResource()
    • Initializes with initializeMint2
  • mint() / transfer()
  • Authority management:
    • updateTokenMintAuthority()
    • updateTokenAccountAuthority()
  • ERC-20-style approval system:
    • approve()
    • claim()
    • revokeApproval()
  • Housekeeping:
    • burn()
    • closeTokenAccount()
    • syncWrappedSOLAccount()

Getters

  • Mint info: getSPLTokenSupply(), getSPLTokenDecimals()
  • Account info: getSPLTokenAccountBalance(), getSPLTokenAccountOwner()
  • ATA/Arbitrary accounts

Practice exercise

Task: Using this library, create an SPL token mint with a new seed and mint tokens from the new mint to an associated token account.

Bonus points for using more functions from this library:

  • Approve a delegate on the new token and let them claim a portion
  • Burn some tokens from the newly created mint
  • Transfer the mint authority of the new token to a different account
  • Empty and then close an account associated with the new mint

Resources

Back to Videos