Skip to main content

light-token -> light-token Account
  • Transfers tokens between light-token accounts
SPL token -> light-token Account
  • Transfers SPL tokens to light-token accounts
  • SPL tokens are locked in interface PDA
  • Tokens are minted to light-token account
light-token -> SPL Account
  • Releases SPL tokens from interface PDA to SPL account
  • Burns tokens in source light-token account

Get Started

The transferInterface function transfers tokens between token accounts (SPL, Token-2022, or Light) in a single call.Compare to SPL:
Find the source code here.
1

Transfer Interface

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 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,
    transferInterface,
    getAssociatedTokenAddressInterface,
} from "@lightprotocol/compressed-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();

    const { mint } = await createMintInterface(rpc, payer, payer, null, 9);

    const sender = Keypair.generate();
    await createAtaInterface(rpc, payer, mint, sender.publicKey);
    const senderAta = getAssociatedTokenAddressInterface(mint, sender.publicKey);
    await mintToInterface(rpc, payer, mint, senderAta, payer, 1_000_000_000);

    const recipient = Keypair.generate();
    await createAtaInterface(rpc, payer, mint, recipient.publicKey);
    const recipientAta = getAssociatedTokenAddressInterface(mint, recipient.publicKey);

    const tx = await transferInterface(rpc, payer, senderAta, mint, recipientAta, sender, 500_000_000);

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

Next Steps

Learn how to close light-token accounts