Skip to main content

  • Wrap: Move tokens from SPL/Token 2022 account → Light Token ATA (hot balance)
  • Unwrap: Move tokens from Light Token ATA (hot balance) → SPL/Token 2022 account
Find the source code: wrap.ts | unwrap.ts
Install the agent skill:
npx skills add https://zkcompression.com
See the AI tools guide for dedicated skills.
1

Wrap SPL Tokens to Light Token ATA

Install packages in your working directory:
npm install @lightprotocol/stateless.js@beta \
            @lightprotocol/compressed-token@beta
Install the CLI globally:
npm install -g @lightprotocol/zk-compression-cli@beta
# start local test-validator in a separate terminal
light test-validator
In the code examples, use createRpc() without arguments for localnet.
import "dotenv/config";
import { Keypair } from "@solana/web3.js";
import { createRpc } from "@lightprotocol/stateless.js";
import {
    createMintInterface,
    createAtaInterface,
    mintToInterface,
    decompressInterface,
    wrap,
    getAssociatedTokenAddressInterface,
    createAtaInterfaceIdempotent,
} from "@lightprotocol/compressed-token";
import {
    createAssociatedTokenAccount,
    TOKEN_2022_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!}`;
// 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 () {
    // Setup: Get SPL tokens (needed to wrap)
    const { mint } = await createMintInterface(rpc, payer, payer, null, 9);
    await createAtaInterface(rpc, payer, mint, payer.publicKey);
    const destination = getAssociatedTokenAddressInterface(
        mint,
        payer.publicKey
    );
    await mintToInterface(rpc, payer, mint, destination, payer, 1000);
    const splAta = await createAssociatedTokenAccount(
        rpc,
        payer,
        mint,
        payer.publicKey,
        undefined,
        TOKEN_2022_PROGRAM_ID
    );
    await decompressInterface(rpc, payer, payer, mint, 1000);

    // Wrap SPL tokens to light-token associated token account
    const lightTokenAta = getAssociatedTokenAddressInterface(
        mint,
        payer.publicKey
    );
    await createAtaInterfaceIdempotent(rpc, payer, mint, payer.publicKey);

    const tx = await wrap(rpc, payer, splAta, lightTokenAta, payer, mint, 500);

    console.log("Tx:", tx);
})();

Transfer interface

Payments overview


Didn’t find what you were looking for?

Reach out! Telegram | email | Discord