> ## Documentation Index
> Fetch the complete documentation index at: https://luminouslabs-cc5545c6-indexing-tokens.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="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, bn } from "@lightprotocol/stateless.js";
        import {
            createMint,
            mintTo,
            loadAta,
            getAssociatedTokenAddressInterface,
        } from "@lightprotocol/compressed-token";
        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 createMint(rpc, payer, payer.publicKey, 9);
            await mintTo(rpc, payer, mint, payer.publicKey, payer, bn(1000));

            // 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,
            bn,
            buildAndSignTx,
            sendAndConfirmTx,
        } from "@lightprotocol/stateless.js";
        import {
            createMint,
            mintTo,
            createLoadAtaInstructions,
            getAssociatedTokenAddressInterface,
        } from "@lightprotocol/compressed-token";
        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: mint directly to cold state
            const { mint } = await createMint(rpc, payer, payer.publicKey, 9);
            await mintTo(rpc, payer, mint, payer.publicKey, payer, bn(1000));

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

            // load from cold to hot state
            const ixs = await createLoadAtaInstructions(
                rpc,
                lightTokenAta,
                payer.publicKey,
                mint,
                payer.publicKey
            );

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

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