Creating a Token-2022 on Solana
Quickly mint a Token-2022 compliant SPL token on Solana Devnet or Mainnet using the command-line interface (CLI).
This guide explains how to quickly mint a Token-2022 compliant SPL token on Solana Devnet using the command-line interface (CLI). It also shows how to enable and use token extensions such as metadata and transfer fees.
Prerequisites
Install Solana CLI
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
Install SPL Token CLI (must support Token-2022)
cargo install spl-token-cli
Set Up Solana CLI for Devnet
solana config set --url https://api.devnet.solana.com solana config set --keypair /path/to/your/dev-wallet.json
Airdrop Some SOL for Fees
solana airdrop 2
Step-by-Step Token-2022 Minting
1. Create a Token-2022 Mint
spl-token create-token \
--program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
Save the returned token mint address.
2. Create a Token Account for Your Wallet
spl-token create-account <TOKEN_MINT_ADDRESS> \
--program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
3. Mint Tokens to Your Account
spl-token mint <TOKEN_MINT_ADDRESS> 1000 \
--program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
4. Confirm Token Balance
spl-token accounts --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
Adding Token Extensions
Token-2022 supports advanced features called extensions. Below are examples of two useful ones.
Extension 1: Transfer Fee
This allows collecting fees on every token transfer.
Create Mint with Transfer Fee Extension
spl-token create-token \
--program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb \
--enable-extensions transferFeeConfig
Initialize Transfer Fee
spl-token enable-transfer-fee \
<TOKEN_MINT_ADDRESS> \
--transfer-fee-config-authority <YOUR_WALLET_ADDRESS> \
--transfer-fee-basis-points 25 \
--maximum-transfer-fee 10
This sets a 0.25% fee (25 basis points) with a max of 10 tokens per transfer.
Extension 2: Metadata
This enables rich token metadata like name, symbol, and image.
Initialize Metadata
spl-token initialize-metadata <TOKEN_MINT_ADDRESS> \
"My Test Token" "MTT" "https://example.com/token-metadata.json"
Make sure the JSON metadata file at that URL is hosted and follows the standard format.
Resources
Token-2022 Documentation: https://spl.solana.com/token-2022
Solana Devnet Explorer: https://explorer.solana.com?cluster=devnet
Notes
You must use the
--program-id Tokenz...
flag for all Token-2022 interactions.Some extensions require initializing during the token mint creation.
Not all wallets or exchanges currently support Token-2022 tokens.
Happy minting!
Last updated