Overview
- Add nanopayments to an existing
x402ResourceServerso it offers gas-free payments alongside your current payment flows. - Your existing payment setup continues to work unchanged. The server includes
nanopayment options in its
402responses in addition to the options your facilitator already supports, and buyers choose whichever method they have funded.
Prerequisites
Before you begin, ensure you have:- An existing x402 seller using
@x402/expressor@x402/corewithx402ResourceServer. - Node.js v18+ installed.
Steps
Step 1. Install the SDK
Step 2. Add BatchFacilitatorClient to your server
Add BatchFacilitatorClient alongside your existing HTTPFacilitatorClient.
Each facilitator handles a different payment type — your existing facilitator
continues to handle standard onchain payments, and BatchFacilitatorClient
handles Gateway payments:
Step 3. Register GatewayEvmScheme
Replace ExactEvmScheme with GatewayEvmScheme. GatewayEvmScheme extends
ExactEvmScheme, so standard onchain payments continue to work. It also
preserves the extra metadata (such as verifyingContract) that Gateway
clients need for EIP-712 signing:
402 responses include Gateway nanopayment
options in the accepts array alongside any options your existing facilitator
supports.
Step 4. Route through a custom facilitator (optional)
If you run your own x402 facilitator that supports Gateway (see facilitator integration), you can route payments through it instead of connecting to Circle Gateway directly. UsefacilitatorUrl with createGatewayMiddleware:
Step 5. Check your balance and withdraw
After buyers pay for your resources, funds accumulate in your Gateway balance. UseGatewayClient to check your earnings and withdraw:
Gateway handles settlement automatically. When you call
settle() in the
middleware, the payment is submitted for batched processing. Your Gateway
available balance increases after the batch settles onchain.Step 6. Verify the integration
The server’s402 responses should now include Gateway options alongside
standard options. Check the accepts array for entries with:
See also
- Use nanopayments with x402 for a summary of all integration paths
- x402 buyer integration for the client-side counterpart
- SDK reference for
GatewayEvmSchemeandBatchFacilitatorClientAPI details