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 and wallet secret. The API key authenticates your server to the CDP Facilitator; the wallet secret lets the SDK provision the wallet that receives payments.
  • Node.js 22 or later.
Set your credentials in the environment before running anything:

1. Install the SDKs

The CDP SDK handles the receiving wallet and 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 receive payments in your CDP wallet.
createX402Server does the whole setup in one call: it provisions the receiver wallet, connects to the CDP Facilitator, registers the payment schemes and extensions, and returns a compliant x402 server object that any x402 framework adapter accepts.
Every route you add to routes is protected; everything else stays free.

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. 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 wallets, 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 wallet? See Production configuration.