How to Mint Compressed Tokens
Complete guide to mint compressed tokens with `mintTo()`, troubleshooting, and advanced configurations.
The mintTo()
function creates compressed token accounts for recipients and increases the mint's token supply. Only the mint authority can perform this operation.
The mintTo()
function
Mints SPL tokens to token pool PDA, the for compression and decompression of tokens
Create compressed accounts containing mint, owner, and amount for each recipient
Before minting compressed tokens, you need an SPL mint registered with the compressed token program via createMint()
for a new mint, or createTokenPool()
for an existing mint.
import { mintTo } from '@lightprotocol/compressed-token';
import { PublicKey } from '@solana/web3.js';
// Use existing mint with token pool for compression to mint compressed tokens
const mint = new PublicKey("MINT_ADDRESS");
const recipient = new PublicKey("RECIPIENT_WALLET_ADDRESS");
const amount = 1_000_000_000; // 1 token (9 decimals)
// Mint compressed tokens - mints SPL tokens to pool, creates compressed token accounts
const transactionSignature = await mintTo(
rpc,
payer,
mint, // SPL mint with token pool for compression
recipient, // recipient address (toPubkey parameter)
payer, // mint authority
amount,
);
Full Code Example
Minting Compressed Tokens
Run this script to mint compressed tokens to a recipient!
// 1. Setup funded payer and connect to local validator
// 2. Create SPL mint with token pool for compression
// 3. Call mintTo() with mint, recipient, and amount - mint SPL tokens to pool and create compressed token accounts
// 4. Verify via getCompressedTokenAccountsByOwner
import { Keypair, PublicKey } from '@solana/web3.js';
import { createRpc } from '@lightprotocol/stateless.js';
import { createMint, mintTo } from '@lightprotocol/compressed-token';
async function mintCompressedTokens() {
// Step 1: Setup funded payer and connect to local validator
const rpc = createRpc(); // defaults to localhost:8899
const payer = Keypair.generate();
const airdropSignature = await rpc.requestAirdrop(payer.publicKey, 1000000000); // 1 SOL
await rpc.confirmTransaction(airdropSignature);
// Step 2: Create SPL mint with token pool for compression
const { mint, transactionSignature: mintCreateTx } = await createMint(
rpc,
payer,
payer.publicKey, // mint authority
9
);
console.log("Mint with token pool for compression created!");
console.log("Mint address:", mint.toBase58());
console.log("Create mint transaction:", mintCreateTx);
// Generate recipient keypair
const recipient = Keypair.generate();
// Define amount to mint
const mintAmount = 1_000_000_000; // 1 token with 9 decimals
// Step 3: Call mintTo() with mint, recipient, and amount
// Mint SPL tokens to pool and create compressed token account
const transactionSignature = await mintTo(
rpc,
payer,
mint, // SPL mint with token pool for compression
recipient.publicKey,
payer, // mint authority
mintAmount
);
console.log("\nCompressed token minted!");
console.log("Recipient:", recipient.publicKey.toBase58());
console.log("Compressed Token Balance:", mintAmount / 1_000_000_000, "tokens");
console.log("Mint token transaction:", transactionSignature);
// Step 4: Verify via getCompressedTokenAccountsByOwner
const tokenAccounts = await rpc.getCompressedTokenAccountsByOwner(
recipient.publicKey,
{ mint }
);
if (tokenAccounts.items.length > 0) {
const balance = tokenAccounts.items[0].parsed.amount; }
return { transactionSignature, recipient: recipient.publicKey, amount: mintAmount };
}
mintCompressedTokens().catch(console.error);
Success!
You've successfully minted compressed tokens. The output shows:
Compressed token supply: Increased the total supply of your mint
Compressed token balance
Troubleshooting
Advanced Configuration
Next Steps
Learn how to transfer compressed tokens you just minted.
How to Transfer Compressed TokenLast updated