Skip to main content

  1. loadAta unifies tokens from multiple sources to a single ATA:
    • Compressed tokens (cold) -> Decompresses -> light ATA
    • SPL balance (if wrap=true) -> Wraps -> light ATA
    • T22 balance (if wrap=true) -> Wraps -> light ATA
  2. Returns null if there’s nothing to load (idempotent)
  3. Creates the ATA if it doesn’t exist
Find the source code here.

Get Started

1

Load Compressed Tokens to Hot Balance

import { Keypair } from "@solana/web3.js";
import { createRpc, bn } from "@lightprotocol/stateless.js";
import {
  createMint,
  mintTo,
  loadAta,
  getAssociatedTokenAddressInterface,
} from "@lightprotocol/compressed-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
  );

  await mintTo(rpc, payer, mint, owner.publicKey, mintAuthority, bn(1000));

  // Get c-token ATA address
  const ctokenAta = getAssociatedTokenAddressInterface(mint, owner.publicKey);

  // Load compressed tokens to hot balance
  // Creates ATA if needed, returns null if nothing to load
  const signature = await loadAta(
    rpc,
    ctokenAta,
    owner,
    mint,
    payer
  );

  if (signature) {
    console.log("Loaded tokens to hot balance");
    console.log("Transaction:", signature);
  } else {
    console.log("Nothing to load");
  }
}

main().catch(console.error);