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);