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 Base exact, Permit2-based EVM upto, and EVM-only auth-capture by
default. Add other EVM networks, Solana (exact and upto), and EVM batch-settlement through
its networkSchemes option:upto uses an escrow payment channel instead of Permit2.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.