Skip to main content
This page documents the public API of the @circle-fin/x402-batching package, which provides buyer and seller integrations for Circle Gateway nanopayments.

Buyer APIs

GatewayClient

The primary client for buyers. Handles deposits, gasless payments, withdrawals, and balance queries.

Constructor

Properties

deposit(amount, options?)

Deposits USDC from your wallet into the Gateway Wallet contract. This is an onchain transaction that requires gas. Returns Promise<DepositResult>:

pay<T>(url, options?)

Pays for an x402-protected resource. Handles the full 402 negotiation flow automatically: sends the request, receives payment requirements, signs the authorization, and retries with the payment header. Returns Promise<PayResult<T>>:

withdraw(amount, options?)

Withdraws USDC from Gateway to your wallet. Supports same-chain (instant) and crosschain withdrawals. Returns Promise<WithdrawResult>:

getBalances(address?)

Returns both the wallet’s USDC balance and the Gateway balance. Returns Promise<Balances>:

supports(url)

Checks whether a URL supports Gateway batching before attempting payment. Returns Promise<SupportsResult>:

getTransferById(id)

Fetches a single x402 transfer by its UUID. Returns Promise<TransferResponse>:

searchTransfers(params?)

Searches x402 transfers with optional filters and paginated results. When network is omitted, the client defaults to its own blockchain. Returns Promise<SearchTransfersResponse>:
self, first, prev, and next are full pagination URLs parsed from the HTTP Link header. pageAfter and pageBefore are the cursor values extracted from those URLs, which you can pass back into searchTransfers() when requesting the next or previous page. Use pagination.pageAfter or pagination.pageBefore to request adjacent pages.

BatchEvmScheme

A SchemeNetworkClient implementation for Circle Gateway batched payments. Use this when integrating with an existing x402Client instance or building a custom payment flow.

Constructor

createPaymentPayload(x402Version, paymentRequirements)

Creates a signed payment payload by constructing and signing an EIP-3009 TransferWithAuthorization message. Returns Promise<PaymentPayload>.

CompositeEvmScheme

Routes payment requests between Gateway batched payments and standard onchain payments. Use this when your client needs to support both payment methods simultaneously.

Constructor

Behavior

  • If the payment requirements include extra.name === "GatewayWalletBatched", delegates to batchScheme.
  • Otherwise, delegates to fallbackScheme.

Usage


registerBatchScheme

Helper that registers a BatchEvmScheme with an x402Client. If you need to support both Gateway and standard onchain exact payments, pass a fallbackScheme so one registration handles both paths:

Seller APIs

createGatewayMiddleware

Creates Express-compatible middleware that handles x402 payment negotiation, verification, and settlement.

Configuration

require(price)

Returns Express middleware that requires payment for the route. The middleware attaches payment information to req.payment:

BatchFacilitatorClient

A FacilitatorClient implementation that communicates with Circle Gateway’s x402 endpoints. Use this for custom server frameworks or when you need fine-grained control over verification and settlement.

Constructor

verify(payload, requirements)

Verifies a payment signature through the Gateway API. Returns Promise<VerifyResponse>:

settle(payload, requirements)

Submits a payment for batched settlement through the Gateway API. This is the recommended method for production flows because it has low latency and guarantees settlement. Returns Promise<SettleResponse>:

getSupported()

Fetches the payment kinds (networks and contract addresses) supported by Gateway. Returns Promise<SupportedResponse>:

GatewayEvmScheme

Server-side EVM scheme that extends ExactEvmScheme with Gateway-specific behavior. Required when using x402ResourceServer with BatchFacilitatorClient.

Constructor

No parameters required. On construction, it automatically registers USDC money parsers for all Gateway-supported networks.

Key behaviors

  • enhancePaymentRequirements(): Merges extra metadata (verifyingContract, name, version) from supported kinds into payment requirements. Sets maxTimeoutSeconds to 604900 (7 days plus a small buffer) for batched settlement.
  • USDC money parsers: Automatically converts dollar amounts to USDC atomic units (6 decimals) for all supported networks using the USDC addresses from CHAIN_CONFIGS.
The base ExactEvmScheme discards the extra field from supported kinds when building payment requirements. Gateway clients require extra.verifyingContract to construct valid EIP-712 signatures. GatewayEvmScheme preserves this data.

Usage


Utilities

supportsBatching

Checks whether a PaymentRequirements object supports Gateway batched settlement. Returns true if the requirements include the GatewayWalletBatched scheme.

isBatchPayment

Server-side alias for supportsBatching. Use this in facilitator routing logic to determine whether a payment should be routed to Gateway.

getVerifyingContract

Extracts the Gateway Wallet contract address from a PaymentRequirements object.

Constants


Chain configuration

  • CHAIN_CONFIGS: Full configuration (USDC address, Gateway Wallet address, RPC URL) for all supported blockchains, keyed by SupportedChainName.
  • GATEWAY_DOMAINS: Gateway domain IDs for EIP-712 signing, keyed by chain name.
Use these constants to retrieve the correct addresses programmatically instead of hardcoding them:
For reference, the Gateway Wallet and USDC contract addresses for each chain are listed in the EVM contract addresses and USDC contract addresses pages.

Error reference

Gateway API error codes

These are the errorReason (settle) and invalidReason (verify) values returned by the Gateway API:

GatewayClient errors

All errors are thrown as standard Error objects with descriptive messages.

Middleware errors

BatchFacilitatorClient errors

BatchEvmScheme errors