@circle-fin/x402-batching package,
which provides buyer and seller integrations for Circle Gateway nanopayments.
Buyer APIs
GatewayClient
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
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
Constructor
Behavior
- If the payment requirements include
extra.name === "GatewayWalletBatched", delegates tobatchScheme. - Otherwise, delegates to
fallbackScheme.
Usage
registerBatchScheme
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
Configuration
require(price)
Returns Express middleware that requires payment for the route.
The middleware attaches payment information to
req.payment:
BatchFacilitatorClient
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
ExactEvmScheme with Gateway-specific
behavior. Required when using x402ResourceServer with
BatchFacilitatorClient.
Constructor
Key behaviors
enhancePaymentRequirements(): Mergesextrametadata (verifyingContract,name,version) from supported kinds into payment requirements. SetsmaxTimeoutSecondsto604900(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
PaymentRequirements object supports Gateway batched
settlement. Returns true if the requirements include the
GatewayWalletBatched scheme.
isBatchPayment
supportsBatching. Use this in facilitator routing logic
to determine whether a payment should be routed to Gateway.
getVerifyingContract
PaymentRequirements
object.
Constants
Chain configuration
CHAIN_CONFIGS: Full configuration (USDC address, Gateway Wallet address, RPC URL) for all supported blockchains, keyed bySupportedChainName.GATEWAY_DOMAINS: Gateway domain IDs for EIP-712 signing, keyed by chain name.
Error reference
Gateway API error codes
These are theerrorReason (settle) and invalidReason (verify) values
returned by the Gateway API:
GatewayClient errors
All errors are thrown as standard Error objects with descriptive messages.