x402ResourceServer so it accepts them
alongside your current onchain payment methods. Your existing payment setup
continues to work unchanged: the server includes nanopayment options in its
402 responses in addition to what your facilitator already supports, and
buyers choose whichever method they have funded. For the client-side
counterpart, see the
x402 buyer integration.
Prerequisites
Before you begin, ensure that you’ve:- Set up an x402 seller with
@x402/expressor@x402/coreusingx402ResourceServer. - Installed Node.js v18+.
Steps
1
Install the SDK
2
Wire in Gateway settlement alongside your existing facilitator
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:3
Advertise Gateway options in your 402 responses
Replace After initialization, the server’s
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.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. Use
facilitatorUrl with createGatewayMiddleware:5
Check your balance and withdraw
After buyers pay for your resources, funds accumulate in your Gateway
balance. Use Withdraw to your wallet on the same blockchain or to a different one:To trace individual payments back to the requests that triggered them, see
Reconcile nanopayments.
GatewayClient to check your earnings using the
Get Token Balances API
endpoint and withdraw using the
Create Transfer Attestation
API endpoint: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.6
Verify the integration
Send an unauthenticated request to a protected route to trigger a The header value is a base64-encoded JSON payload. After decoding, the
If both standard and Gateway entries appear in
402
response, then inspect the PAYMENT-REQUIRED header:accepts array should include an entry where extra.name is
"GatewayWalletBatched":accepts, the server is
correctly offering both payment methods.