Skip to main content
This guide takes you from nothing to one successful server-side paid API call. You will pay for a protected endpoint with test USDC on Base testnet, using a CDP-managed wallet, so there is no private key to store anywhere. CDP SDK wallets run on your backend. Use this path when you are:
  • Building an agent that autonomously pays for API services.
  • Adding x402 payments to an application backend.
  • Building a managed wallet or payment flow for your users.
Building a browser or full-stack payment flow? Use x402 payments with Embedded Wallets when users should pay from their own self-custodial wallets.Want an agent to pay without writing payment code? Start with Agentic Accounts.
New to the protocol? How x402 works explains the request, the 402 response, and the payment that follows.
Using a coding agent? Install the matching skill and your agent runs this guide in your own project:

Prerequisites

Set your credentials in the environment before running anything:

1. Install the SDKs

The CDP SDK handles the wallet. The x402 packages handle the protocol.

2. Write the client

The client resolves a CDP-managed wallet, prints the address that pays, and then requests a protected endpoint. The wrapper handles the 402 response, payment, and retry.
CdpX402Client provisions the wallet and registers payment schemes for you, then plugs into wrapFetchWithPayment from @x402/fetch.

3. (Optional) Fund the wallet

Run the client once:
It prints the address it pays from and then fails, because the wallet holds no USDC yet:
Send test USDC on Base testnet to that address. The fastest route is the Faucets quickstart, which covers both the CDP Portal and the API. To claim it in code with the credentials you already exported:

4. Make the paid call

Wait for the faucet transaction to confirm, then run the client again:
An HTTP 200 means the payment was verified and settled, and you received the protected resource. You paid for an API without an account, an invoice, or a card.

Runnable examples

Complete versions of the client include faucet funding and settlement details: You paid a service you already knew about. To find services you don’t, browse the catalog in Discover services. Where you go next depends on what you are building: