Skip to main content
A delegate is an address that you authorize to spend from your Unified Balance on a given blockchain. In practice, a delegate is often a backend service signing spends on behalf of a user. How delegates work:
  • Delegation is blockchain-specific.
  • Authorizing a delegate on one blockchain does not grant them access on other blockchains.
  • An authorized delegate can call spend with sourceAccount set to your address so funds are drawn from your Unified Balance.
You can check, add, and remove delegates at any time. For an end-to-end flow on how a delegate can deposit and spend from a Unified Balance, see the delegate quickstart.

Prerequisites

Before you begin, ensure that you’ve: These are required so any example below runs with a valid kit and adapter.

Check delegate status

The following example reads delegate status for an address.
TypeScript
import { AppKit } from "@circle-fin/app-kit";
import { createViemAdapterFromPrivateKey } from "@circle-fin/adapter-viem-v2";

const kit = new AppKit();

const adapter = createViemAdapterFromPrivateKey({
  privateKey: process.env.EVM_PRIVATE_KEY as string,
});

const status = await kit.unifiedBalance.getDelegateStatus({
  from: { adapter, chain: "Base_Sepolia" },
  delegateAddress: "0xDelegateAddress",
});

console.log("Delegate status:", status); // 'none' | 'pending' | 'ready'
getDelegateStatus resolves to 'none' when no delegate is set, 'pending' while delegation is still confirming, and 'ready' when the delegate is active and authorized to spend.

Poll until ready

Use getDelegateStatus in a poll loop to wait until the delegate is active before spending. Confirmation time varies by blockchain. For example, on Ethereum, Base, and Arbitrum it can take up to 15 minutes, while on Arc and Avalanche it is near-instant. If the delegate was added well before the spend, getDelegateStatus returns 'ready' immediately and no polling is needed. This example polls until the delegate is ready before spending:
TypeScript
import { AppKit } from "@circle-fin/app-kit";
import { createViemAdapterFromPrivateKey } from "@circle-fin/adapter-viem-v2";

const kit = new AppKit();

const adapter = createViemAdapterFromPrivateKey({
  privateKey: process.env.EVM_PRIVATE_KEY as string,
});

let status = await kit.unifiedBalance.getDelegateStatus({
  from: { adapter, chain: "Base_Sepolia" },
  delegateAddress: "0xDelegateAddress",
});

while (status === "pending") {
  await new Promise((r) => setTimeout(r, 10_000)); // wait 10 seconds
  status = await kit.unifiedBalance.getDelegateStatus({
    from: { adapter, chain: "Base_Sepolia" },
    delegateAddress: "0xDelegateAddress",
  });
}

if (status === "ready") {
  console.log("Delegate is ready. Safe to spend.");
}

Add a delegate

The following example authorizes a delegate to spend from a Unified Balance on Base Sepolia.
TypeScript
import { AppKit } from "@circle-fin/app-kit";
import { createViemAdapterFromPrivateKey } from "@circle-fin/adapter-viem-v2";

const kit = new AppKit();

const adapter = createViemAdapterFromPrivateKey({
  privateKey: process.env.EVM_PRIVATE_KEY as string,
});

await kit.unifiedBalance.addDelegate({
  from: { adapter, chain: "Base_Sepolia" },
  delegateAddress: "0xDelegateAddress",
});

console.log("Delegate added.");
Delegation is blockchain-specific. To authorize a delegate on multiple blockchains, call addDelegate for each blockchain.

Remove a delegate

This example removes a delegate from a Unified Balance on Base Sepolia:
TypeScript
import { AppKit } from "@circle-fin/app-kit";
import { createViemAdapterFromPrivateKey } from "@circle-fin/adapter-viem-v2";

const kit = new AppKit();

const adapter = createViemAdapterFromPrivateKey({
  privateKey: process.env.EVM_PRIVATE_KEY as string,
});

await kit.unifiedBalance.removeDelegate({
  from: { adapter, chain: "Base_Sepolia" },
  delegateAddress: "0xDelegateAddress",
});

console.log("Delegate removed.");