When to Use Custom Tokens
Use custom tokens when:- You’re building a token-gated service
- You want to accept payments in your project’s native token
- You’re testing with test tokens on devnet
- You have a specific tokenomics model
- You need stable value for payments
- You want maximum compatibility with existing payment systems
- You’re building general-purpose payment applications
Full Example
Step-by-Step Breakdown
1. Lookup Token Mint
lookupKnownSPLToken to find USDC, but you can use any mint address:
2. Create Wallet
3. Create Payment Handler with Mint
createPaymentHandler is called with a mint parameter. This tells the handler to use that specific SPL token for payments.
4. Make Payment
- Create an SPL token transfer instruction
- Transfer tokens from your associated token account
- Submit the transaction
- Retry the original request with payment proof
Using Custom Tokens
Option 1: Create Your Own Token
See Creating a Test Token for instructions on creating a custom SPL token on devnet. Once created, use its mint address:Option 2: Use Existing Token
You can use any SPL token mint address:Token Payment vs SOL Payment
- Token: Requires associated token accounts, specific token mint
- SOL: No token accounts needed, simpler but price volatile
Prerequisites
Before making token payments:- Token must exist: The mint must be created on the network
- Token account exists: Your wallet needs an associated token account for the mint
- Sufficient balance: Your token account must have enough tokens for the payment
- Create associated token accounts if needed (if you provide a connection)
- Check balances
- Handle account creation automatically
Environment Variables
PAYER_KEYPAIR_PATH: Path to your Solana keypair JSON file
Related Resources
- Creating a Test Token - How to create custom tokens
- Solana Exact Payment - USDC payment with connection
- SOL Payment - Native SOL payment example