- Wrap: Move tokens from SPL/T22 account → light-token ATA (hot balance)
- Unwrap: Move tokens from light-token ATA (hot balance) → SPL/T22 account
Find the source code: wrap.test.ts | unwrap.test.ts
Get Started
- Wrap
- Unwrap
1
Wrap SPL Tokens to Light-Token ATA
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();
await rpc.requestAirdrop(payer.publicKey, 10e9);
const owner = Keypair.generate();
await rpc.requestAirdrop(owner.publicKey, 1e9);
const mintAuthority = Keypair.generate();
const mintKeypair = Keypair.generate();
const { mint } = await createMint(
rpc,
payer,
mintAuthority.publicKey,
9,
mintKeypair
);
const splAta = await createAssociatedTokenAccount(
rpc,
payer,
mint,
owner.publicKey
);
// Mint compressed then decompress to SPL ATA
await mintTo(rpc, payer, mint, owner.publicKey, mintAuthority, bn(1000));
await decompress(rpc, payer, mint, bn(1000), owner, splAta);
// Create c-token ATA (destination)
const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey);
await createAtaInterfaceIdempotent(rpc, payer, mint, owner.publicKey);
// Wrap SPL tokens to c-token ATA
const signature = await wrap(
rpc,
payer,
splAta,
ctokenAta,
owner,
mint,
bn(500)
);
console.log("Wrapped 500 tokens to c-token ATA");
console.log("Transaction:", signature);
}
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();
await rpc.requestAirdrop(payer.publicKey, 10e9);
const owner = Keypair.generate();
await rpc.requestAirdrop(owner.publicKey, 1e9);
const mintAuthority = Keypair.generate();
const mintKeypair = Keypair.generate();
const { mint } = await createMint(
rpc,
payer,
mintAuthority.publicKey,
9,
mintKeypair
);
// Mint compressed tokens to owner
await mintTo(rpc, payer, mint, owner.publicKey, mintAuthority, bn(1000));
// Create destination SPL ATA (must exist before unwrap)
const splAta = await createAssociatedTokenAccount(
rpc,
payer,
mint,
owner.publicKey
);
// Unwrap c-tokens to SPL ATA
// This auto-loads compressed tokens to hot balance first
const signature = await unwrap(
rpc,
payer,
splAta,
owner,
mint,
bn(500)
);
console.log("Unwrapped 500 tokens to SPL ATA");
console.log("Transaction:", signature);
}
main().catch(console.error);

