Skip to main content
// 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,
);

Get Started

1

Mint Compressed Tokens

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 } from "@solana/web3.js";
import { createRpc } from "@lightprotocol/stateless.js";
import { createMint, mintTo } from "@lightprotocol/compressed-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 mint
    const { mint } = await createMint(rpc, payer, payer.publicKey, 9);

    // Mint compressed tokens
    const recipient = Keypair.generate();
    const tx = await mintTo(rpc, payer, mint, recipient.publicKey, payer, 1_000_000_000);

    console.log("Mint:", mint.toBase58());
    console.log("Recipient:", recipient.publicKey.toBase58());
    console.log("Tx:", tx);
})();
Make sure the SPL mint has a token pool for compression.
The script creates this token pool for you.
For development, you can create a new mint with token pool via createMint() or add a token pool to an existing mint via createTokenPool().

Troubleshooting

// Error message: "TokenPool not found. Please create a compressed token
// pool for mint: [ADDRESS] via createTokenPool().
The mint does no have a token pool for compression. Ensure you created the mint using createMint.
// Create mint with token pool for compression
import { createMint } from '@lightprotocol/compressed-token';
const { mint } = await createMint(rpc, payer, payer.publicKey, 9);
The token pool info doesn’t correspond to the mint address. Ensure you’re fetching the correct pool:
// Get the correct token pool for your mint
const tokenPoolInfo = await getTokenPoolInfos(rpc, mint);
When minting to multiple recipients, ensure arrays are the same size.
// Wrong: Mismatched array lengths
const recipients = [addr1, addr2, addr3];
const amounts = [100, 200]; // Only 2 amounts for 3 recipients

// Correct: Same length arrays
const recipients = [addr1, addr2, addr3];
const amounts = [100, 200, 300]; // 3 amounts for 3 recipients

Advanced Configuration

// Mint different amounts to multiple recipients
const recipients = [
    Keypair.generate().publicKey,
    Keypair.generate().publicKey,
    Keypair.generate().publicKey,
];

const amounts = [
    1_000_000_000, // 1 token
    2_000_000_000, // 2 tokens
    500_000_000,   // 0.5 tokens
];

const transactionSignature = await mintTo(
    rpc,
    payer,
    mint, // SPL mint with token pool for compression
    recipients, // array of recipients (toPubkey parameter)
    payer, // mint authority
    amounts, // array of amounts (amount parameter)
);
Mint tokens using a custom mint authority with approveAndMintTo():
import { approveAndMintTo } from '@lightprotocol/compressed-token';

// Mint tokens with a separate mint authority
const transactionSignature = await approveAndMintTo(
    rpc,
    payer,
    mint, // SPL mint with token pool for compression
    recipient.publicKey, // recipient of minted tokens (toPubkey parameter)
    mintAuthority, // mint authority
    mintAmount,
);

Next Steps

How to Transfer Compressed Tokens