- Wrap: Move tokens from SPL/T22 account → light-token ATA (hot balance)
- Unwrap: Move tokens from light-token ATA (hot balance) → SPL/T22 account
Get Started
- Wrap
- Unwrap
1
Wrap SPL Tokens to Light Token ATA
Installations
Installations
- npm
- yarn
- pnpm
Install packages in your working directory:Install the CLI globally:
Report incorrect code
Copy
Ask AI
npm install @lightprotocol/stateless.js@alpha \
@lightprotocol/compressed-token@alpha
Report incorrect code
Copy
Ask AI
npm install -g @lightprotocol/zk-compression-cli@alpha
Install packages in your working directory:Install the CLI globally:
Report incorrect code
Copy
Ask AI
yarn add @lightprotocol/stateless.js@alpha \
@lightprotocol/compressed-token@alpha
Report incorrect code
Copy
Ask AI
yarn global add @lightprotocol/zk-compression-cli@alpha
Install packages in your working directory:Install the CLI globally:
Report incorrect code
Copy
Ask AI
pnpm add @lightprotocol/stateless.js@alpha \
@lightprotocol/compressed-token@alpha
Report incorrect code
Copy
Ask AI
pnpm add -g @lightprotocol/zk-compression-cli@alpha
Report incorrect code
Copy
Ask AI
# Start local test-validator in separate terminal
light test-validator
Report incorrect code
Copy
Ask AI
import { Keypair } from "@solana/web3.js";
import { createRpc, bn } from "@lightprotocol/stateless.js";
import {
createMint,
mintTo,
decompress,
wrap,
getAssociatedTokenAddressInterface,
createAtaInterfaceIdempotent,
} from "@lightprotocol/compressed-token";
import { createAssociatedTokenAccount } from "@solana/spl-token";
async function main() {
const rpc = createRpc();
const payer = Keypair.generate();
const sig = await rpc.requestAirdrop(payer.publicKey, 10e9);
await rpc.confirmTransaction(sig);
// Setup: Get SPL tokens (needed to wrap)
const { mint } = await createMint(rpc, payer, payer.publicKey, 9);
const splAta = await createAssociatedTokenAccount(rpc, payer, mint, payer.publicKey);
await mintTo(rpc, payer, mint, payer.publicKey, payer, bn(1000));
await decompress(rpc, payer, mint, bn(1000), payer, splAta);
// Wrap SPL tokens to rent-free token ATA
const ctokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey);
await createAtaInterfaceIdempotent(rpc, payer, mint, payer.publicKey);
const tx = await wrap(rpc, payer, splAta, ctokenAta, payer, mint, bn(500));
console.log("Tx:", tx);
}
main().catch(console.error);
1
Unwrap Light Tokens to SPL Account
Report incorrect code
Copy
Ask AI
import { Keypair } from "@solana/web3.js";
import { createRpc, bn } from "@lightprotocol/stateless.js";
import { createMint, mintTo } from "@lightprotocol/compressed-token";
import { unwrap } from "@lightprotocol/compressed-token/unified";
import { createAssociatedTokenAccount } from "@solana/spl-token";
async function main() {
const rpc = createRpc();
const payer = Keypair.generate();
const sig = await rpc.requestAirdrop(payer.publicKey, 10e9);
await rpc.confirmTransaction(sig);
// Setup: Get compressed tokens (cold storage)
const { mint } = await createMint(rpc, payer, payer.publicKey, 9);
await mintTo(rpc, payer, mint, payer.publicKey, payer, bn(1000));
// Unwrap rent-free tokens to SPL ATA
const splAta = await createAssociatedTokenAccount(rpc, payer, mint, payer.publicKey);
const tx = await unwrap(rpc, payer, splAta, payer, mint, bn(500));
console.log("Tx:", tx);
}
main().catch(console.error);