Create an interface PDA for compression for an existing SPL mint. createTokenPool() requires only fee_payer and has no mint authority constraint.
The interface PDA itself requires rent, but individual compressed token accounts are rent-free.
function-create-token-pool.ts
// Creates interface PDA for existing SPL mint
const transactionSignature = await createTokenPool (
rpc ,
payer ,
mint ,
);
Best Practice: Each mint supports a maximum of 4 interface PDAs total. During compression/decompression operations, interface PDAs get write-locked. Use addTokenPools() to create additional PDAs that increase per-block write-lock capacity.
Get Started
Create Interface PDA
Install packages in your working directory: npm install @lightprotocol/stateless.js@^0.23.0 \
@lightprotocol/compressed-token@^0.23.0
Install the CLI globally: npm install -g @lightprotocol/zk-compression-cli
Install packages in your working directory: yarn add @lightprotocol/stateless.js@^0.23.0 \
@lightprotocol/compressed-token@^0.23.0
Install the CLI globally: yarn global add @lightprotocol/zk-compression-cli
Install packages in your working directory: pnpm add @lightprotocol/stateless.js@^0.23.0 \
@lightprotocol/compressed-token@^0.23.0
Install the CLI globally: pnpm add -g @lightprotocol/zk-compression-cli
Install packages in your working directory: # npm
npm install @lightprotocol/stateless.js@^0.23.0 \
@lightprotocol/token-interface@^0.1.2
# yarn
yarn add @lightprotocol/stateless.js@^0.23.0 \
@lightprotocol/token-interface@^0.1.2
# pnpm
pnpm add @lightprotocol/stateless.js@^0.23.0 \
@lightprotocol/token-interface@^0.1.2
Install the CLI globally: npm install -g @lightprotocol/zk-compression-cli
# 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 , 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 interface PDA 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 an interface PDA that doesn’t exist. // Create the missing interface PDA
const poolTx = await createTokenPool ( rpc , payer , mint );
console . log ( "Interface PDA 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 Pool with Token-2022
Create interface PDAs 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