-
loadAtaunifies 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
-
Returns
nullif there’s nothing to load (idempotent) - Creates the ATA if it doesn’t exist
Find the source code here.
Get Started
1
Load Compressed Tokens to Hot Balance
Installations
Installations
- npm
- yarn
- pnpm
Install packages in your working directory:Install the CLI globally:
npm install @lightprotocol/stateless.js@alpha \
@lightprotocol/compressed-token@alpha
npm install -g @lightprotocol/zk-compression-cli@alpha
Install packages in your working directory:Install the CLI globally:
yarn add @lightprotocol/stateless.js@alpha \
@lightprotocol/compressed-token@alpha
yarn global add @lightprotocol/zk-compression-cli@alpha
Install packages in your working directory:Install the CLI globally:
pnpm add @lightprotocol/stateless.js@alpha \
@lightprotocol/compressed-token@alpha
pnpm add -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,
loadAta,
getAssociatedTokenAddressInterface,
} from "@lightprotocol/compressed-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 compressed tokens (cold storage)
const { mint } = await createMint(rpc, payer, payer.publicKey, 9);
await mintTo(rpc, payer, mint, payer.publicKey, payer, bn(1000));
// Load compressed tokens to hot balance
const ctokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey);
const tx = await loadAta(rpc, ctokenAta, payer, mint, payer);
console.log("Tx:", tx);
}
main().catch(console.error);
import "dotenv/config";
import { Keypair, ComputeBudgetProgram } from "@solana/web3.js";
import { createRpc, bn, buildAndSignTx, sendAndConfirmTx } from "@lightprotocol/stateless.js";
import { createMint, mintTo, createLoadAtaInstructions, getAssociatedTokenAddressInterface } from "@lightprotocol/compressed-token";
import { homedir } from "os";
import { readFileSync } from "fs";
const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`;
const payer = Keypair.fromSecretKey(
new Uint8Array(
JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8"))
)
);
(async function () {
const rpc = createRpc(RPC_URL);
// Setup: Get compressed tokens (cold storage)
const { mint } = await createMint(rpc, payer, payer.publicKey, 9);
await mintTo(rpc, payer, mint, payer.publicKey, payer, bn(1000));
// Create load instructions to move tokens from cold to hot balance
const ctokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey);
const ixs = await createLoadAtaInstructions(rpc, ctokenAta, payer.publicKey, mint, payer.publicKey);
if (ixs.length === 0) {
console.log("Nothing to load");
return;
}
const { blockhash } = await rpc.getLatestBlockhash();
const tx = buildAndSignTx(
[ComputeBudgetProgram.setComputeUnitLimit({ units: 500_000 }), ...ixs],
payer,
blockhash
);
const signature = await sendAndConfirmTx(rpc, tx);
console.log("Tx:", signature);
})();