How to Create Compressed Token Pools for Mint Accounts
Complete guide to create and manage token pools for compressed tokens for SPL mints with `createTokenPool()`, troubleshooting and advanced configurations.
The createTokenPool()
function registers an existing SPL mint with the compressed token program and creates a token pool PDA. createTokenPool()
requires only fee_payer
and has no mint authority constraint.
The function
registers an existing SPL mint with the compressed token program and
create token pool PDA with
createTokenPoolInstruction
, the omnibus account that holds SPL tokens corresponding to compressed tokens in circulation
Before we create a token pool, we need an existing SPL mint account.
Best Practice: Each mint supports a maximum of 4 token pools total. During compression/decompression operations, token pools get write-locked. Use addTokenPools()
to create additional pools to increase per-block write-lock capacity.
import { createTokenPool } from '@lightprotocol/compressed-token';
import { PublicKey } from '@solana/web3.js';
const mint = new PublicKey("YOUR_EXISTING_SPL_MINT_ADDRESS");
// Registers existing SPL mint with compressed token program, creates token pool account
const transactionSignature = await createTokenPool(
rpc,
payer,
mint,
);
Full Code Example
Creating Token Pools
Run this script to create token pools for an SPL mint!
// 1. Setup funded payer and connect to local validator
// 2. Create SPL mint
// 3. Call createTokenPool() to register mint with compressed token program
// 4. Add additional pools to increase write-lock capacity (optional)
import { Keypair, PublicKey } from '@solana/web3.js';
import { createRpc } from '@lightprotocol/stateless.js';
import { createTokenPool, addTokenPools } from '@lightprotocol/compressed-token';
import { createMint } from '@solana/spl-token';
async function createTokenPools() {
// 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
const mint = await createMint(
rpc,
payer,
payer.publicKey, // mint authority
payer.publicKey, // freeze authority
9
);
console.log("SPL mint created");
console.log("Mint address:", mint.toBase58());
// Step 3: Call createTokenPool() to register SPL mint with compressed token program
// Creates token pool PDA (omnibus account) that holds SPL tokens for compressed tokens
const poolTx = await createTokenPool(
rpc,
payer,
mint // existing SPL mint to register
);
console.log("\nToken pool created!");
console.log("SPL mint registered with compressed token program:", mint.toBase58());
console.log("Pool transaction:", poolTx);
// Step 4: Add up to 3 additional pools - increase write-lock capacity for higher throughput
const additionalPoolsCount = 2;
const additionalPoolsTx = await addTokenPools(
rpc,
payer,
mint, // SPL mint with existing token pool
additionalPoolsCount, // number of additional pools (max 3 more)
);
console.log(`\nAdded ${additionalPoolsCount} additional token pools!`);
console.log("Additional pools transaction:", additionalPoolsTx);
return {
mint,
poolTransaction: poolTx,
additionalPoolsTransaction: additionalPoolsTx
};
}
createTokenPools().catch(console.error);
Success!
You've created multiple token pools for an SPL mint. The output shows:
Token pool creation: Omnibus account registered for compression/decompression
Additional pools: Multiple pools created for increased write-lock limit per block
Transaction confirmations: All pool creation operations confirmed on-chain
Troubleshooting
Advanced Configuration
Next Steps
Learn how to approve and revoke delegate authority for compressed token accounts.
How to approve and revoke delegate authorityLast updated