Overview
- Add nanopayments as a settlement provider to your x402 facilitator so that sellers connected to your facilitator automatically gain access to gas-free, batched payments.
- Use this guide if you operate an x402 facilitator service and want to offer Gateway settlement alongside your existing onchain settlement methods.
This guide is for infrastructure providers and payment processors running x402
facilitators.
Prerequisites
Before you begin, ensure you have:- An existing x402 facilitator service using
@x402/core. - Node.js v18+ installed.
- Familiarity with the x402 protocol and how facilitators verify and settle payments.
Steps
Step 1. Install the SDK
Install@circle-fin/x402-batching alongside its required peer dependencies:
Step 2. Initialize the BatchFacilitatorClient
The BatchFacilitatorClient handles all communication with Circle Gateway,
including verification, settlement, and supported-network discovery.
Step 3. Route payments by type
Your facilitator acts as a router. UseisBatchPayment() to detect Gateway
payments and delegate them to the BatchFacilitatorClient. Route all other
payments to your existing onchain logic.
Gateway payments are identified by the extra metadata field:
extra.name === "GatewayWalletBatched".
Gateway’s
settle() endpoint is optimized for low latency and guarantees
settlement. Use settle() directly rather than calling verify() followed by
settle() in production flows.Step 4. Wire up HTTP endpoints
Expose your routing logic through standard x402 facilitator endpoints:Step 5. Connect sellers to your facilitator
Once your facilitator supports Gateway, sellers connect to it and automatically gain access to both standard and gas-free payment options.Using x402ResourceServer
Sellers using x402ResourceServer connect to your facilitator with
HTTPFacilitatorClient:
Using createGatewayMiddleware
Sellers using the Gateway middleware can route verification and settlement
through your facilitator by setting facilitatorUrl:
Alternative: Gas-free-only facilitator
If you are building a new facilitator that only needs to support gas-free payments (without standard onchain settlement), useBatchFacilitatorClient
directly with x402ResourceServer:
Using GatewayEvmScheme with x402ResourceServer
When using x402ResourceServer with BatchFacilitatorClient, register
GatewayEvmScheme to ensure payment requirements include the metadata that
Gateway clients need for EIP-712 signing. GatewayEvmScheme extends the
standard ExactEvmScheme to:
- Preserve
extrametadata (verifyingContract,name,version) in payment requirements - Set
maxTimeoutSecondsto 345600 (4 days) for batched settlement - Register USDC money parsers for all Gateway-supported networks
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.See also
- SDK reference for
BatchFacilitatorClientandGatewayEvmSchemeAPI details - Seller quickstart for setting up a
seller with
createGatewayMiddleware - How batched settlement works for background on the batching lifecycle