> ## Documentation Index
> Fetch the complete documentation index at: https://www.zkcompression.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Delegated Transfer

> Transfer tokens as an approved delegate. The delegate signs instead of the owner, spending within the approved allowance.

`transferInterface` with `{ owner }` transfers tokens from an associated token account as an approved delegate. The delegate is the transaction authority. Only the delegate and fee payer sign; the owner's signature is not required.

* The recipient is a wallet address (associated token account derived and created internally)
* The amount must be within the approved allowance
* Each transfer reduces the remaining allowance

<Accordion title="Agent skill">
  Install or view [dedicated agent skills](/ai-tools/overview#agent-skills).

  ```
  npx skills add Lightprotocol/skills
  ```

  Install orchestrator agent skill or view [skill.md](https://www.zkcompression.com/skill.md):

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

<Tabs>
  <Tab title="Guide">
    <Steps>
      <Step>
        ### Delegated Transfer

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

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

              Install the CLI globally:

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

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

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

              Install the CLI globally:

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

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

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

              Install the CLI globally:

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

            <Tab title="SDK 2.0 (token-interface)">
              Install packages in your working directory:

              ```bash theme={null}
              # npm
              npm install @lightprotocol/stateless.js@^0.23.0 \
                          @lightprotocol/token-interface@^0.1.2

              # yarn
              yarn add @lightprotocol/stateless.js@^0.23.0 \
                       @lightprotocol/token-interface@^0.1.2

              # pnpm
              pnpm add @lightprotocol/stateless.js@^0.23.0 \
                       @lightprotocol/token-interface@^0.1.2
              ```

              Install the CLI globally:

              ```bash theme={null}
              npm install -g @lightprotocol/zk-compression-cli
              ```
            </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 { Keypair } from "@solana/web3.js";
            import {
                approveInterface,
                transferInterface,
            } from "@lightprotocol/compressed-token/unified";
            import { rpc, payer, setup } from "../setup.js";

            (async function () {
                const { mint, senderAta } = await setup();

                // Approve: grant delegate permission to spend up to 500,000 tokens
                const delegate = Keypair.generate();
                await approveInterface(
                    rpc,
                    payer,
                    senderAta,
                    mint,
                    delegate.publicKey,
                    500_000,
                    payer
                );
                console.log("Approved delegate:", delegate.publicKey.toBase58());

                // Delegate transfers tokens on behalf of the owner
                const recipient = Keypair.generate();
                const tx = await transferInterface(
                    rpc,
                    payer,
                    senderAta,
                    mint,
                    recipient.publicKey,
                    payer.publicKey,
                    delegate,
                    200_000
                );

                console.log("Delegated transfer to:", recipient.publicKey.toBase58());
                console.log("Amount: 200,000 tokens");
                console.log("Tx:", tx);
            })();
            ```
          </Tab>

          <Tab title="Instruction">
            ```typescript theme={null}
            import {
                Keypair,
                Transaction,
                sendAndConfirmTransaction,
            } from "@solana/web3.js";
            import { createTransferInterfaceInstructions } from "@lightprotocol/compressed-token/unified";
            import { rpc, payer, setup } from "../setup.js";

            (async function () {
                const { mint } = await setup();

                const delegate = Keypair.generate();
                const recipient = Keypair.generate();

                // Returns TransactionInstruction[][]. Each inner array is one txn.
                const instructions = await createTransferInterfaceInstructions(
                    rpc,
                    payer.publicKey,
                    mint,
                    200_000,
                    payer.publicKey,
                    recipient.publicKey,
                    9,
                    { delegatePubkey: delegate.publicKey }
                );

                for (const ixs of instructions) {
                    const tx = new Transaction().add(...ixs);
                    const sig = await sendAndConfirmTransaction(rpc, tx, [payer, delegate]);
                    console.log("Tx:", sig);
                }
            })();
            ```
          </Tab>

          <Tab title="SDK 2.0 (token-interface)">
            ```typescript theme={null}
            import { Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js";
            import {
              createApproveInstructions,
              createTransferInstructions,
            } from "@lightprotocol/token-interface";
            import { rpc, payer, setup } from "../setup.js";

            (async function () {
              const { mint } = await setup();
              const delegate = Keypair.generate();
              const recipient = Keypair.generate();

              const approveIxs = await createApproveInstructions({
                rpc,
                payer: payer.publicKey,
                owner: payer.publicKey,
                mint,
                delegate: delegate.publicKey,
                amount: 500_000_000n,
              });
              await sendAndConfirmTransaction(rpc, new Transaction().add(...approveIxs), [payer]);

              const transferIxs = await createTransferInstructions({
                rpc,
                payer: payer.publicKey,
                mint,
                sourceOwner: payer.publicKey,
                authority: delegate.publicKey,
                recipient: recipient.publicKey,
                amount: 200_000_000n,
              });
              const sig = await sendAndConfirmTransaction(
                rpc,
                new Transaction().add(...transferIxs),
                [payer, delegate]
              );
              console.log("Tx:", sig);
            })();
            ```
          </Tab>
        </Tabs>
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Related Guides

<CardGroup cols={2}>
  <Card title="Approve and revoke" icon="key" href="/light-token/cookbook/approve-revoke" horizontal />

  <Card title="Payments overview" icon="credit-card" href="/light-token/payments/overview" horizontal />
</CardGroup>

***

## Didn't find what you were looking for?

<Callout type="info">
  Reach out! [Telegram](https://t.me/swen_light) | [email](mailto:support@lightprotocol.com) | [Discord](https://discord.com/invite/7cJ8BhAXhu)
</Callout>
