Skip to main content

  • 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.ts | unwrap.ts

Get Started

1

Wrap SPL Tokens to Light Token ATA

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 separate terminal
light test-validator
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);