Skip to main content
This guide takes you from an unprotected HTTP route to an x402-gated endpoint with one successful payment.
Selling products to people and agents? The Business Checkouts API creates one checkout with a hosted payment URL for people and an x402_url for agents. Use it to support both payment flows without running your own x402 server or facilitator. See Accept agentic payments with x402.Charging for an MCP tool instead? Follow Charge over MCP. This quickstart covers HTTP routes.
Using a coding agent? Install the matching skill and your agent runs this guide in your own project:

Prerequisites

  • A CDP API key. The API key authenticates your server to the CDP Facilitator for verify and settle. It does not decide where funds land.
  • A payTo address that can receive the asset on each network you advertise. The CDP Facilitator settles on multiple EVM networks and on Solana: one EVM address covers every EVM network you list; Solana needs a separate Solana address. Examples in this guide use a single EVM address on Base Sepolia. See Pay-to address.
  • Node.js 22 or later.
Set the facilitator credentials and your receiving address before running anything:
If you have no receiving address, create one following the alternate path.

Pay-to address

Set X402_PAY_TO to an onchain address that can receive the asset. Use one you already control: a CDP custodial wallet, a CDP non-custodial wallet, Coinbase Prime, Coinbase Business, a Coinbase retail deposit address, or a wallet you custody. This guide uses Base Sepolia; switch to a mainnet address in production. See Configure who receives payment.

1. Install the SDKs

The CDP SDK authenticates the facilitator. The x402 packages handle the protocol and the framework middleware.
This guide uses Express. For Hono and Next.js, see Runnable examples.

2. Price a route

The following servers charge $0.01 for GET /report and settle to X402_PAY_TO.
createX402Server connects to the CDP Facilitator, registers payment schemes, and returns a server object that any x402 framework adapter accepts. payToConfig with type: "address" sends funds to the address you provide.
Every route you add to routes is protected; everything else stays free. To accept Solana as well, pass solana on payToConfig (a Solana address, not the EVM one) and include a solana: network on the route. See supported networks.
If you do not already have a receiving address, CDP can create one. This replaces the address path above rather than adding to it: the SDK provisions an API Key Wallet — the API key variant of CDP non-custodial wallets — and that wallet’s address becomes your payTo. It is not required to sell over x402.Instead of exporting X402_PAY_TO, add a wallet secret:
In server.ts, delete the payTo lookup and its throw, and drop payToConfig so createX402Server provisions the wallet:
The rest of the file is unchanged; server.payToEvmAddress reports the provisioned address.

3. Start the server and confirm x402 is set up

In a new terminal, start the server:
From a second terminal, request the route without paying:
The 402 Payment Required response confirms that the route is protected.

4. Test the payment

Choose either testing path:
  • Ask your agent to use the Pay for Service skill with http://localhost:8402/report.
  • Build a basic client with the buyer quickstart, then point its request at http://localhost:8402/report.
Both paths fund a buyer wallet and make the paid request. A successful call returns HTTP 200.

5. Move to production

After the test payment succeeds, switch the route to a mainnet before accepting real payments:
Routes without an explicit networks list switch from Base Sepolia and Solana Devnet to Base and Solana mainnets.
Confirm that each payTo address can receive funds on its mainnet — for example your Coinbase Business, Prime, or entity deposit address, not a testnet wallet. Dollar prices such as "$0.01" automatically use the network’s default USDC asset. If you specify a token address and amount directly, replace any testnet asset address with its mainnet equivalent and verify its decimals. See Production configuration for custom networks, assets, receiving destinations, and payment schemes.

Runnable examples

Complete versions of the server cover more frameworks:
Your endpoint is priced and paid. The next step is making it discoverable.
  • What settled your payment? CDP Facilitator covers the supported networks, schemes, and pricing.
  • Need production networks, another scheme, or a different receiving destination? See Production configuration.