Documentation Index Fetch the complete documentation index at: https://luminouslabs-cc5545c6-feat-add-zk.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
The mint account itself requires rent (like regular SPL mints), but individual compressed token accounts are rent-free.
Create a token pool for an existing SPL mint with createTokenPool() or use createMint() to create a new one from scratch.
// Create SPL mint with token pool for compression
const { mint , transactionSignature } = await createMint (
rpc ,
payer ,
mintAuthority . publicKey ,
decimals ,
);
Best Practice: Each mint supports a maximum of 4 token pools total. During compression/decompression, token pools get write-locked. Use addTokenPools() to create additional pools that increase per-block write-lock capacity.
Get Started
Create a Mint Account with Token Pool for Compression
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
Install packages in your working directory: yarn add @lightprotocol/stateless.js@alpha \
@lightprotocol/compressed-token@alpha
Install the CLI globally: yarn global add @lightprotocol/zk-compression-cli@alpha
Install packages in your working directory: pnpm add @lightprotocol/stateless.js@alpha \
@lightprotocol/compressed-token@alpha
Install the CLI globally: pnpm add -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.
Get an API key from Helius and add to .env: API_KEY =< your-helius-api-key >
In the code examples, use createRpc(RPC_URL) with the devnet URL.
import "dotenv/config" ;
import { Keypair } from "@solana/web3.js" ;
import { createRpc } from "@lightprotocol/stateless.js" ;
import { createMint } 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();
const { mint , transactionSignature } = await createMint (
rpc ,
payer ,
payer . publicKey ,
9
);
console . log ( "Mint:" , mint . toBase58 ());
console . log ( "Tx:" , transactionSignature );
})();
import "dotenv/config" ;
import {
Keypair ,
ComputeBudgetProgram ,
PublicKey ,
Transaction ,
sendAndConfirmTransaction ,
} from "@solana/web3.js" ;
import {
createRpc ,
getBatchAddressTreeInfo ,
selectStateTreeInfo ,
CTOKEN_PROGRAM_ID ,
} from "@lightprotocol/stateless.js" ;
import { createMintInstruction } from "@lightprotocol/compressed-token" ;
import { homedir } from "os" ;
import { readFileSync } from "fs" ;
const COMPRESSED_MINT_SEED = Buffer . from ( "compressed_mint" );
function findMintAddress ( mintSigner : PublicKey ) : [ PublicKey , number ] {
return PublicKey . findProgramAddressSync (
[ COMPRESSED_MINT_SEED , mintSigner . toBuffer ()],
CTOKEN_PROGRAM_ID
);
}
// devnet:
const RPC_URL = `https://devnet.helius-rpc.com?api-key= ${ process . env . API_KEY ! } ` ;
const rpc = createRpc ( RPC_URL );
// localnet:
// const rpc = createRpc();
const payer = Keypair . fromSecretKey (
new Uint8Array (
JSON . parse ( readFileSync ( ` ${ homedir () } /.config/solana/id.json` , "utf8" ))
)
);
( async function () {
const mintSigner = Keypair . generate ();
const addressTreeInfo = getBatchAddressTreeInfo ();
const stateTreeInfo = selectStateTreeInfo ( await rpc . getStateTreeInfos ());
const [ mintPda ] = findMintAddress ( mintSigner . publicKey );
const validityProof = await rpc . getValidityProofV2 (
[],
[{ address: mintPda . toBytes (), treeInfo: addressTreeInfo }]
);
const ix = createMintInstruction (
mintSigner . publicKey ,
9 ,
payer . publicKey ,
null ,
payer . publicKey ,
validityProof ,
addressTreeInfo ,
stateTreeInfo
);
const tx = new Transaction (). add (
ComputeBudgetProgram . setComputeUnitLimit ({ units: 1_000_000 }),
ix
);
const signature = await sendAndConfirmTransaction ( rpc , tx , [ payer , mintSigner ]);
console . log ( "Mint:" , mintPda . toBase58 ());
console . log ( "Tx:" , signature );
})();
Advanced Configuration
Customize who can mint new compressed tokens. const mintAuthority = Keypair . generate ();
const { mint , transactionSignature } = await createMint (
rpc ,
payer ,
mintAuthority . publicKey ,
9 ,
);
Customize who can freeze/thaw compressed token accounts. const freezeAuthority = Keypair . generate ();
const { mint , transactionSignature } = await createMint (
rpc ,
payer ,
payer . publicKey , // mint authority
9 , // decimals
Keypair . generate (), // mint keypair
undefined , // confirm options
undefined , // token program ID
freezeAuthority . publicKey , // freeze authority
);
Next Steps
How to Add Token Pools for Existing Mints