Skip to main content
Create a token for compression fo an existing SPL mint. 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.
// Creates token pool account for existing SPL mint
const 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.

Get Started

1

Create Token Pool

Install packages in your working directory:
npm install @lightprotocol/stateless.js@alpha \
            @lightprotocol/compressed-token@alpha
Install the CLI globally:
npm install -g @lightprotocol/zk-compression-cli@alpha
# start local test-validator in a separate terminal
light test-validator
In the code examples, use createRpc() without arguments for localnet.
import "dotenv/config";
import { Keypair, PublicKey } from "@solana/web3.js";
import { createRpc } from "@lightprotocol/stateless.js";
import { createTokenPool } from "@lightprotocol/compressed-token";
import { createMint as createSplMint, TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { homedir } from "os";
import { readFileSync } from "fs";

// devnet:
const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`;
// localnet:
// const RPC_URL = undefined;
const payer = Keypair.fromSecretKey(
    new Uint8Array(
        JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8"))
    )
);

(async function () {
    // devnet:
    const rpc = createRpc(RPC_URL);
    // localnet:
    // const rpc = createRpc();

    // Setup: Create existing SPL mint
    const mintKeypair = Keypair.generate();
    await createSplMint(rpc, payer, payer.publicKey, null, 9, mintKeypair, undefined, TOKEN_PROGRAM_ID);

    // Create token pool for existing mint
    const tx = await createTokenPool(rpc, payer, mintKeypair.publicKey);

    console.log("Mint:", mintKeypair.publicKey.toBase58());
    console.log("Tx:", tx);
})();

Troubleshooting

You’re trying to access a token pool that doesn’t exist.
// Create the missing token pool
const poolTx = await createTokenPool(rpc, payer, mint);
console.log("Token pool created:", poolTx);

Advanced Configuration

Create pools for multiple mints:
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 token pools for Token-2022 mints:
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token';

const poolTx = await createTokenPool(
    rpc,
    payer,
    mint, // Token-2022 mint
    undefined,
    TOKEN_2022_PROGRAM_ID,
);

Next Steps

How to Merge Compressed Token Accounts