Skip to main content

  1. Approve grants a delegate permission to transfer up to a specified amount of tokens from your account.
    • Each token account can have only one delegate at a time.
    • Any new approval overwrites the previous one.
  2. Revoke removes all delegate permissions from a Light Token account.
  3. Only the token account owner can approve or revoke delegates.
Install the agent skill:
npx skills add https://zkcompression.com
See the AI tools guide for dedicated skills.
approveInterface grants a delegate permission to transfer up to a specified amount of tokens.
1

Prerequisites

Install packages in your working directory:
npm install @lightprotocol/stateless.js@beta \
            @lightprotocol/compressed-token@beta
Install the CLI globally:
npm install -g @lightprotocol/zk-compression-cli@beta
# start local test-validator in a separate terminal
light test-validator
In the code examples, use createRpc() without arguments for localnet.
2

Approve or revoke delegates

Find the source code: delegate-approve.ts | delegate-revoke.ts
import "dotenv/config";
import { Keypair } from "@solana/web3.js";
import { createRpc } from "@lightprotocol/stateless.js";
import {
    createMintInterface,
    mintToCompressed,
    getAssociatedTokenAddressInterface,
} from "@lightprotocol/compressed-token";
import { approveInterface } 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 () {
    const { mint } = await createMintInterface(rpc, payer, payer, null, 9);
    await mintToCompressed(rpc, payer, mint, payer, [
        { recipient: payer.publicKey, amount: 1000n },
    ]);

    const senderAta = getAssociatedTokenAddressInterface(mint, payer.publicKey);
    const delegate = Keypair.generate();
    const tx = await approveInterface(
        rpc,
        payer,
        senderAta,
        mint,
        delegate.publicKey,
        500_000,
        payer
    );

    console.log("Approved delegate:", delegate.publicKey.toBase58());
    console.log("Allowance: 500,000 tokens");
    console.log("Tx:", tx);
})();

Delegated transfer

Payments overview


Didn’t find what you were looking for?

Reach out! Telegram | email | Discord