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

# Load Token Balances to Light Associated Token Account

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

1. `loadAta` unifies tokens from multiple sources to a single ATA:
   * Compressed tokens (cold Light Tokens) -> 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/main/js/compressed-token/src/v3/actions/load-ata.ts).
</Info>

<Accordion title="Agent skill">
  Install the [agent skill](https://zkcompression.com/skill.md):

  ```bash theme={null}
  npx skills add https://zkcompression.com
  ```

  See the [AI tools guide](/ai-tools/guide) for dedicated skills.
</Accordion>

<Steps>
  <Step>
    ### Unify Tokens to Light-ATA Balance

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

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

          Install the CLI globally:

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

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

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

          Install the CLI globally:

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

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

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

          Install the CLI globally:

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

    <Tabs>
      <Tab title="Localnet">
        ```bash theme={null}
        # start local test-validator in a separate terminal
        light test-validator
        ```

        <Note>
          In the code examples, use `createRpc()` without arguments for localnet.
        </Note>
      </Tab>

      <Tab title="Devnet">
        Get an API key from [Helius](https://helius.dev) and add to `.env`:

        ```bash title=".env" theme={null}
        API_KEY=<your-helius-api-key>
        ```

        <Note>
          In the code examples, use `createRpc(RPC_URL)` with the devnet URL.
        </Note>
      </Tab>
    </Tabs>

    <Tabs>
      <Tab title="Action">
        ```typescript theme={null}
        import "dotenv/config";
        import { Keypair } from "@solana/web3.js";
        import { createRpc } from "@lightprotocol/stateless.js";
        import {
            createMintInterface,
            mintToCompressed,
            loadAta,
            getAssociatedTokenAddressInterface,
        } from "@lightprotocol/compressed-token/unified";
        import { homedir } from "os";
        import { readFileSync } from "fs";

        // devnet:
        const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`;
        const rpc = createRpc(RPC_URL);
        // localnet:
        // const rpc = createRpc();

        const payer = Keypair.fromSecretKey(
            new Uint8Array(
                JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8"))
            )
        );

        (async function () {
            // Setup: Get compressed tokens (cold storage)
            const { mint } = await createMintInterface(rpc, payer, payer, null, 9);
            await mintToCompressed(rpc, payer, mint, payer, [
                { recipient: payer.publicKey, amount: 1000n },
            ]);

            // Load compressed tokens to hot balance
            const lightTokenAta = getAssociatedTokenAddressInterface(mint, payer.publicKey);
            const tx = await loadAta(rpc, lightTokenAta, payer, mint, payer);

            console.log("Tx:", tx);
        })();
        ```
      </Tab>

      <Tab title="Instruction">
        ```typescript theme={null}
        import "dotenv/config";
        import { Keypair } from "@solana/web3.js";
        import {
            createRpc,
            buildAndSignTx,
            sendAndConfirmTx,
        } from "@lightprotocol/stateless.js";
        import {
            createMintInterface,
            mintToCompressed,
            createLoadAtaInstructions,
            getAssociatedTokenAddressInterface,
        } from "@lightprotocol/compressed-token/unified";
        import { homedir } from "os";
        import { readFileSync } from "fs";

        // devnet:
        // const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`;
        // const rpc = createRpc(RPC_URL);
        // localnet:
        const rpc = createRpc();

        const payer = Keypair.fromSecretKey(
            new Uint8Array(
                JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8")),
            ),
        );

        (async function () {
            // Inactive Light Tokens are cryptographically preserved on the Solana ledger
            // as compressed tokens (cold storage)
            // Setup: Get compressed tokens in light-token associated token account
            const { mint } = await createMintInterface(rpc, payer, payer, null, 9);
            await mintToCompressed(rpc, payer, mint, payer, [{ recipient: payer.publicKey, amount: 1000n }]);

            const lightTokenAta = getAssociatedTokenAddressInterface(
                mint,
                payer.publicKey,
            );

            // Load compressed tokens to light associated token account (hot balance). Usually one tx. Empty = noop.
            const instructions = await createLoadAtaInstructions(
                rpc,
                lightTokenAta,
                payer.publicKey,
                mint,
                payer.publicKey,
            );

            if (instructions.length === 0) return console.log("Nothing to load");

            for (const ixs of instructions) {
                const { blockhash } = await rpc.getLatestBlockhash();
                const tx = buildAndSignTx(ixs, payer, blockhash);
                const sig = await sendAndConfirmTx(rpc, tx);
                console.log("Tx:", sig);
            }
        })();
        ```
      </Tab>
    </Tabs>
  </Step>
</Steps>
