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

> ## Agent Instructions
> Before reading these docs, install the relevant Circle Skill to get pre-loaded context — skills are LLM-optimized and cover architecture decisions, correct flows, and common pitfalls. In Claude Code: run /plugin marketplace add circlefin/skills then /plugin install circle-skills@circle. With Vercel Skills CLI: run npx skills add circlefin/skills. Available skills: use-usdc https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-usdc/SKILL.md (balances, transfers, approvals on EVM and Solana); EURC has no skill — see https://developers.circle.com/stablecoins/what-is-eurc.md; bridge-stablecoin https://github.com/circlefin/skills/blob/master/plugins/circle/skills/bridge-stablecoin/SKILL.md (crosschain transfers via CCTP, USDC, EURC, and third-party assets); use-arc https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-arc/SKILL.md (Arc chain config, contract deployment, USDC bridging — Arc docs: https://docs.arc.io/llms.txt); use-circle-wallets https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-circle-wallets/SKILL.md (choose wallet type); use-developer-controlled-wallets https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-developer-controlled-wallets/SKILL.md (custodial wallets for payouts and treasury); use-user-controlled-wallets https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-user-controlled-wallets/SKILL.md (embedded wallets with Web2 login); use-modular-wallets https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-modular-wallets/SKILL.md (smart contract wallets with passkeys and ERC-4337); use-gateway https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-gateway/SKILL.md (unified USDC balance, nanopayments); use-smart-contract-platform https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-smart-contract-platform/SKILL.md (deploy, interact, monitor contracts). Pair any skill with the Circle MCP server for live SDK signatures, contract addresses, and chain IDs: {"mcpServers":{"circle":{"url":"https://api.circle.com/v1/codegen/mcp"}}}.
> Read the product overview first. Each product has an overview explaining when and why to use it. Read it before quickstarts.
> Pick the right wallet type. Developer-controlled (you hold keys), user-controlled (end user holds keys via PIN/social login), or modular (smart contract wallets with passkeys). See https://developers.circle.com/wallets.md.
> Use CCTP V2 for crosschain transfers. CCTP natively transfers USDC and EURC via burn-and-mint, and supports permissionless wrapping of third-party assets via lock-and-mint. V1 is legacy; always use V2 unless V1 is specified or the chain requires it (Noble, Sui, and Aptos still require V1). Migration guide: https://developers.circle.com/cctp/migration-from-v1-to-v2.md.
> Use Bridge Kit for frontend bridging. Wraps CCTP with a simpler SDK for user-facing apps. Use CCTP directly for backend transfers.
> Gas Station vs Paymaster. Gas Station sponsors gas for Circle Wallet transactions. Paymaster lets users pay gas in USDC. Different use cases — read both overviews.
> Gateway Nanopayments for sub-cent payments. Gasless USDC micropayments down to $0.000001 via x402 and batched settlement. For pay-per-request APIs, AI agent payments, streaming.
> Look up USDC addresses per chain. Never hardcode — use https://developers.circle.com/stablecoins/usdc-contract-addresses.md.
> Prefer SDKs over raw API calls. Node.js and Python SDKs handle auth, retries, and errors.
> API key required. Bearer token in Authorization header. Testnet and mainnet use separate keys and may use different base URLs depending on the product.
> Set up webhooks when available. Most operations are async. Webhooks deliver transaction confirmations and state changes.
> When calling list endpoints, paginate using pageSize and pageAfter until no nextPageAfter cursor is returned—stopping at the first page silently misses records.
> Building an AI agent? Start with the Agent Stack—Circle CLI, agent wallets, and nanopayments built for autonomous use cases: https://developers.circle.com/agent-stack.md.

# How-to: Add nanopayments to an x402 buyer

> Add gas-free nanopayments to your x402 client alongside standard onchain payments

Add gas-free nanopayments to an existing x402 client so it can pay without gas
when a server supports it, and fall back to standard onchain payments when it
does not. Gas-free payments require a one-time USDC deposit into a Gateway
Wallet contract. After that, every subsequent payment is an offchain signature
with zero gas cost. For the server-side counterpart, see the
[x402 seller integration](/gateway-nanopayments/howtos/x402-seller).

## Prerequisites

Before you begin, ensure that you've:

* Set up an x402 client using `@x402/core`.
* Installed [Node.js](https://nodejs.org/) v18+.
* Generated an EVM wallet private key for signing.
* Funded the wallet with testnet USDC from the
  [Circle Faucet](https://faucet.circle.com) so you can deposit into Gateway.

## Steps

<Steps>
  <Step title="Install the SDK">
    ```shell theme={null}
    npm install @circle-fin/x402-batching
    ```

    If you plan to use `CompositeEvmScheme` (recommended for supporting both
    payment methods), also install:

    ```shell theme={null}
    npm install @x402/evm
    ```
  </Step>

  <Step title="Enable Gateway payments in your client">
    Pick the approach that matches your setup:

    * **Composite (recommended)**: support both Gateway and onchain payments
      in one client, with automatic routing based on what each server offers.
    * **Existing client**: add Gateway to a client you've already configured,
      with minimal changes and standard onchain payments preserved.

    If you only need gas-free payments and don't need standard onchain
    support, use `GatewayClient` directly. See the
    [buyer quickstart](/gateway-nanopayments/quickstarts/buyer) for a full
    walkthrough.

    <Tabs>
      <Tab title="Composite">
        Use `CompositeEvmScheme` to route automatically based on the server's
        payment requirements. When the server offers a Gateway option, the
        client uses `BatchEvmScheme` for a gas-free payment. When only standard
        onchain options are available, it falls back to `ExactEvmScheme`:

        ```ts theme={null}
        import { ExactEvmScheme } from "@x402/evm/exact/client";
        import {
          CompositeEvmScheme,
          BatchEvmScheme,
        } from "@circle-fin/x402-batching/client";

        const composite = new CompositeEvmScheme(
          new BatchEvmScheme(signer),
          new ExactEvmScheme(signer),
        );

        client.register("eip155:*", composite);
        ```

        No per-request routing code is needed. `CompositeEvmScheme` checks
        each payment option's `extra.name` field and delegates to the correct
        scheme automatically.
      </Tab>

      <Tab title="Existing client">
        If you already have scheme registrations and want to add Gateway
        support with minimal changes while keeping standard onchain payments
        available:

        ```ts theme={null}
        import { ExactEvmScheme } from "@x402/evm/exact/client";
        import { registerBatchScheme } from "@circle-fin/x402-batching/client";

        registerBatchScheme(client, {
          signer: account,
          fallbackScheme: new ExactEvmScheme(account),
        });
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Fund your Gateway balance">
    Before making gas-free payments, deposit USDC from your wallet into the
    Gateway Wallet contract. This is a one-time onchain transaction:

    ```ts theme={null}
    import { GatewayClient } from "@circle-fin/x402-batching/client";

    const gatewayClient = new GatewayClient({
      chain: "arcTestnet",
      privateKey: process.env.PRIVATE_KEY as `0x${string}`,
    });

    const balances = await gatewayClient.getBalances();
    if (balances.gateway.available < 1_000_000n) {
      await gatewayClient.deposit("1");
    }
    ```

    `getBalances()` calls the
    [Get Token Balances](/api-reference/gateway/all/get-token-balances) API
    endpoint. After the deposit confirms, your Gateway balance is available
    for gas-free payments.

    Deposit time depends on the blockchain. See
    [required block confirmations](/gateway/references/supported-blockchains#required-block-confirmations)
    for exact times per blockchain.

    <Tip>
      [Unified Balance](https://docs.arc.io/app-kit/unified-balance) in Arc App Kits offers [fast deposits](https://docs.arc.io/app-kit/tutorials/unified-balance/use-fast-deposits), which credit your Gateway balance in seconds.
    </Tip>
  </Step>

  <Step title="Verify the target server supports Gateway">
    Before attempting a gas-free payment, check whether the target server
    supports Gateway. The `supports()` method requests the target URL, checks
    for a `402` response, and inspects the `PAYMENT-REQUIRED` header for a
    compatible Gateway batching option:

    ```ts theme={null}
    const support = await gatewayClient.supports(
      "https://api.example.com/resource",
    );

    if (!support.supported) {
      console.log("Server does not support Gateway -- falling back to onchain");
    }
    ```

    If you are using `CompositeEvmScheme`, this check is optional since the
    scheme handles fallback automatically.
  </Step>

  <Step title="Withdraw funds back to your wallet (optional)">
    Withdraw USDC from Gateway back to your wallet at any time. Withdrawals
    are instant for both same-blockchain and crosschain destinations. The
    `withdraw()` method calls the
    [Create Transfer Attestation](/api-reference/gateway/all/create-transfer-attestation)
    API endpoint:

    ```ts theme={null}
    await gatewayClient.withdraw("5");

    await gatewayClient.withdraw("5", { chain: "baseSepolia" });
    ```
  </Step>

  <Step title="Look up individual transfers (optional)">
    After paying for resources, you can look up individual transfers using the
    [Get x402 Transfer by ID](/api-reference/gateway-nanopayments/get-x402transfer-by-id)
    API endpoint, or search across transfer history using the
    [Search x402 Transfers](/api-reference/gateway-nanopayments/search-x402transfers)
    API endpoint:

    ```ts theme={null}
    const { transfers, pagination } = await gatewayClient.searchTransfers({
      from: gatewayClient.address,
      status: "received",
      pageSize: 20,
    });

    const transferUUID = transfers[0]?.id;

    if (transferUUID) {
      try {
        const transfer = await gatewayClient.getTransferById(transferUUID);

        console.log({
          id: transfer.id,
          status: transfer.status,
          amount: transfer.amount,
        });
      } catch (error) {
        console.error("Could not load transfer", error);
      }
    }

    if (pagination?.pageAfter) {
      const nextPage = await gatewayClient.searchTransfers({
        from: gatewayClient.address,
        status: "received",
        pageSize: 20,
        pageAfter: pagination.pageAfter,
      });
    }
    ```

    `searchTransfers` supports filtering by sender, recipient, nonce, network,
    status, token, and date range. When you filter by `status`, also provide
    `from`, `to`, or `nonce` to narrow the search. This example uses the
    buyer's address as `from`. When `network` is omitted, the client defaults
    to the client's configured blockchain. See the
    [SDK reference](/sdks/gateway-nanopayments-sdk) for the full list of
    parameters.
  </Step>
</Steps>
