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 token pool account itself requires rent, but individual compressed token accounts are rent-free.
Before we create a token pool, we need an existing SPL mint account.
Copy
Ask AI
// Creates token pool account for existing SPL mintconst transactionSignature = await createTokenPool( rpc, payer, mint,);
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 that increase per-block write-lock capacity.
Developer EnvironmentBy default, this guide uses Localnet.
Copy
Ask AI
# Install the development CLInpm install @lightprotocol/zk-compression-cli
Copy
Ask AI
# Start a local test validatorlight test-validator## ensure you have the Solana CLI accessible in your system PATH
Copy
Ask AI
// createRpc() defaults to local test validator endpointsimport { Rpc, createRpc,} from "@lightprotocol/stateless.js";const connection: Rpc = createRpc();async function main() { let slot = await connection.getSlot(); console.log(slot); let health = await connection.getIndexerHealth(slot); console.log(health); // "Ok"}main();
Alternative: Using DevnetFollow these steps to create an RPC Connection. Replace <your_api_key> with your API key before running.
const mints = [ new PublicKey("MINT_1_ADDRESS"), new PublicKey("MINT_2_ADDRESS"), new PublicKey("MINT_3_ADDRESS"),];for (const mint of mints) { try { const poolTx = await createTokenPool(rpc, payer, mint); console.log(`Pool created for ${mint.toBase58()}:`, poolTx); } catch (error) { console.log(`Failed for ${mint.toBase58()}:`, error.message); }}
Create Pool with Token-2022
Create token pools for Token-2022 mints:
Copy
Ask AI
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token';const poolTx = await createTokenPool( rpc, payer, mint, // Token-2022 mint undefined, TOKEN_2022_PROGRAM_ID,);