Use CDP with an existing x402 client
- TypeScript
- Python
Already have an
x402Client built on @x402/core with your own key? Add a CDP-managed signer
without migrating to CdpX402Client:fromCdpEvmAccount has counterparts for other account types: fromCdpSmartWallet for a Smart
Contract Wallet, and cdpSolanaAccountToSvmSigner for Solana. See
x402DevMigration.ts
for a runnable example.Payment schemes
A scheme is the payment behavior a server asks for, such as charging a fixed amount. The server advertises what it accepts, and your client picks a matching registered scheme.- TypeScript
- Python
CdpX402Client registers exact and upto for you. batch-settlement is opt-in through its
networkSchemes option. The upto scheme uses Permit2, but the CDP Facilitator sponsors that
approval, so the buyer does not need to pay a network fee.For exact signatures and configuration, see the
CDP SDK x402 reference.Set spend limits
Spend controls enforce a client-side budget on top of what the server charges.- TypeScript
- Python
SpendControlError with a machine-readable code.See the full runnable version in
payForApiWithSpendControls.ts.Add onchain attribution
Builder Codes attribute the clients and intermediaries that create x402 payments. The CDP Facilitator records these codes in ERC-8021 Schema 2 calldata when it settles an EVM payment.- TypeScript
- Python
Pass your Builder Code to Composite applications can pass an array to attribute multiple clients or middleware layers.
CdpX402Client:Lifecycle hooks
- TypeScript
- Python
x402HTTPClient provides onPaymentRequired. Its underlying x402Client provides
onBeforePaymentCreation, onAfterPaymentCreation, onPaymentCreationFailure, and
onPaymentResponse. CdpX402Client inherits these hooks.What to read next
- Discover services to find x402 endpoints.
- Discover and pay over MCP to use the same payment flow with MCP tools.