> ## Documentation Index
> Fetch the complete documentation index at: https://luminouslabs-cc5545c6-swen-add-code-runner.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Load Token Balances to Light ATA

> Unify token balances from compressed tokens (cold), SPL, and Token-2022 to one light ATA.

***

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

<Info>
  Find the source code [here](https://github.com/Lightprotocol/light-protocol/blob/0c4e2417b2df2d564721b89e18d1aad3665120e7/js/compressed-token/src/v3/actions/load-ata.ts).
</Info>

## Get Started

<Steps>
  <Step>
    ### Load Compressed Tokens to Hot Balance

    <Accordion title="Installations">
      <Tabs>
        <Tab title="npm">
          Install packages in your working directory:

          ```bash theme={null}
          npm install @lightprotocol/stateless.js@alpha \
                      @lightprotocol/compressed-token@alpha
          ```

          Install the CLI globally:

          ```bash theme={null}
          npm install -g @lightprotocol/zk-compression-cli@alpha
          ```
        </Tab>

        <Tab title="yarn">
          Install packages in your working directory:

          ```bash theme={null}
          yarn add @lightprotocol/stateless.js@alpha \
                   @lightprotocol/compressed-token@alpha
          ```

          Install the CLI globally:

          ```bash theme={null}
          yarn global add @lightprotocol/zk-compression-cli@alpha
          ```
        </Tab>

        <Tab title="pnpm">
          Install packages in your working directory:

          ```bash theme={null}
          pnpm add @lightprotocol/stateless.js@alpha \
                   @lightprotocol/compressed-token@alpha
          ```

          Install the CLI globally:

          ```bash theme={null}
          pnpm add -g @lightprotocol/zk-compression-cli@alpha
          ```
        </Tab>
      </Tabs>
    </Accordion>

    ```bash theme={null}
    # Start local test-validator in separate terminal
    light test-validator
    ```

    <CodeGroup>
      ```typescript Action theme={null}
      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);
      ```

      ```typescript Instruction theme={null}
      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);
      })();
      ```
    </CodeGroup>
  </Step>
</Steps>
