Quickstart for Sellers
Last updated
Last updated
This guide walks you through integrating with x402 to enable payments for your API or service. By the end, your API will be able to charge buyers and AI agents for access.
Before you begin, ensure you have:
A crypto wallet to receive funds (any EVM-compatible wallet, e.g., CDP Wallet)
(optional) A (CDP) account and API Keys
Required for mainnet use until other facilitators go live
and npm installed
An existing API or server
Note We have pre-configured , including examples for Express, Next.js, and Hono. We also have an that shows how to use the x402 SDKs to build a more complex payment flow.
Install the .
Integrate the payment middleware into your application. You will need to provide:
The Facilitator URL or facilitator object. For testing, use https://x402.org/facilitator
which works on Base Sepolia. For mainnet, you can use the facilitator
from @coinbase/x402
.
The routes you want to protect.
Your receiving wallet address.
This is the interface for the payment middleware config:
When a request is made to this route without payment, your server will respond with the HTTP 402 Payment Required code and payment instructions.
To verify:
Make a request to your endpoint (e.g., curl http://localhost:3000/your-endpoint
).
The server responds with a 402 Payment Required, including payment instructions in the body.
Complete the payment using a compatible client, wallet, or automated agent. This typically involves signing a payment payload, which is handled by the client SDK detailed in the Quickstart for Buyers.
Retry the request, this time including the X-PAYMENT
header containing the cryptographic proof of payment (payment payload).
The server verifies the payment via the facilitator and, if valid, returns your actual API response (e.g., { "data": "Your paid API response." }
).
npm install
the dependencies in each example
Get started as a buyer
This quickstart covered:
Installing the x402 SDK and relevant middleware
Adding payment middleware to your API and configuring it
Testing your integration
Your API is now ready to accept crypto payments through x402.
For more information on running in production on mainnet, check out
Full example in the repo .
Full example in the repo . Since this is a fullstack example, we recommend using the example to build this yourself, and treat the code snippet below as a reference.
Full example in the repo .
If you get an error stating Cannot find module 'x402-hono/express' or its corresponding type declarations.
, add the tsconfig.json from the to your project.
Looking for something more advanced? Check out the
For questions or support, join our .