Use CDP with an existing x402 server
- TypeScript
- Python
Already have an x402 server? Add This works with
createCdpFacilitatorClient() for CDP settlement without
migrating to createX402Server. It uses your CDP API key and secret.x402HTTPResourceServer and x402MCPResourceServer. See
server.ts
for a runnable example.Choose your environment
createX402Server supports Base and Solana by default:
"development"uses testnets and test funds."production"uses mainnets and real funds.
- TypeScript
- Python
Routes inherit this setting unless they list specific networks. Switching To accept specific networks, list them on the route:
environment changes
every inherited route:Choose a payment scheme
A payment scheme defines when the amount is determined and how the payment settles:exactcharges a known price for a synchronous endpoint.uptoauthorizes a maximum, then settles the amount used by a synchronous endpoint.batch-settlementsupports repeated, high-throughput payments by redeeming per-request commitments later in batches.
exact unless your endpoint requires usage-based pricing or payment channels.
Configure non-default schemes
- TypeScript
- Python
exact is registered automatically and is the default for every route. To use upto, set it on
the route:batch-settlement requires the full x402 RouteConfig and direct scheme registration. See the
x402 batch-settlement guide.Configure who receives payment
- TypeScript
- Python
By default,
createX402Server provisions a CDP Server Wallet. Use payToConfig to provision a
Smart Contract Wallet or receive payment at an address you provide:Resolve the recipient dynamically
Use the full x402 route format when the receiving address depends on the request:Accept other tokens
Routes can accept tokens other than USDC.- TypeScript
- Python
Use the full x402
RouteConfig to set the asset for each payment option. Check the CDP
Facilitator’s supported networks and tokens first.Add onchain attribution
Builder Codes attribute the application that exposed a paid endpoint. The CDP Facilitator records this code in ERC-8021 Schema 2 calldata when it settles an EVM payment.- TypeScript
- Python
Pass your Builder Code to The server advertises the code on every EVM route. Solana-only routes are skipped because Builder
Code attribution uses EVM calldata.
createX402Server:Lifecycle hooks
- TypeScript
- Python
Use resource-server hooks for payment lifecycle events. Available hooks include
onProtectedRequest, onBeforeVerify, onAfterVerify, onVerifyFailure, onBeforeSettle,
onAfterSettle, onSettleFailure, and onVerifiedPaymentCanceled.What to read next
- CDP Facilitator for supported chains, tokens, and schemes.
- Charge over MCP to protect an MCP tool instead of an HTTP route.