---
title: "Quickstart for Sellers"
description: "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."
---
**Note:** This quickstart begins with testnet configuration for safe testing. When you're ready for production, see [Running on Mainnet](#running-on-mainnet) for the simple changes needed to accept real payments on Base (EVM) and Solana networks.
### Prerequisites
Before you begin, ensure you have:
* A crypto wallet to receive funds (any EVM-compatible wallet)
* [Node.js](https://nodejs.org/en) and npm, [Go](https://go.dev/), or Python and pip installed
* An existing API or server
**Note**\
We have pre-configured examples available in our repo for both [Node.js](https://github.com/coinbase/x402/tree/main/examples/typescript/servers) and [Go](https://github.com/coinbase/x402/tree/main/examples/go/servers). We also have an [advanced example](https://github.com/coinbase/x402/tree/main/examples/typescript/servers/advanced) that shows how to use the x402 SDKs to build a more complex payment flow.
### 1. Install Dependencies
<Tabs>
<Tab title="Express">
Install the [x402 Express middleware package](https://www.npmjs.com/package/@x402/express).
```bash
npm install @x402/express @x402/core @x402/evm
```
</Tab>
<Tab title="Next.js">
Install the [x402 Next.js middleware package](https://www.npmjs.com/package/@x402/next).
```bash
npm install @x402/next @x402/core @x402/evm
```
</Tab>
<Tab title="Hono">
Install the [x402 Hono middleware package](https://www.npmjs.com/package/@x402/hono).
```bash
npm install @x402/hono @x402/core @x402/evm
```
</Tab>
<Tab title="Go">
Add the x402 Go module to your project:
```bash
go get github.com/coinbase/x402/go
```
</Tab>
<Tab title="FastAPI">
[Install the x402 Python package](https://pypi.org/project/x402/) with FastAPI support:
```bash
pip install "x402[fastapi]"
# For Solana support, also add:
pip install "x402[svm]"
```
</Tab>
<Tab title="Flask">
[Install the x402 Python package](https://pypi.org/project/x402/) with Flask support:
```bash
pip install "x402[flask]"
# For Solana support, also add:
pip install "x402[svm]"
```
</Tab>
</Tabs>
### 2. Add Payment Middleware
Integrate the payment middleware into your application. You will need to provide:
* The Facilitator URL or facilitator client. For testing, use `https://x402.org/facilitator` which works on Base Sepolia and Solana devnet.
* For mainnet setup, see [Running on Mainnet](#running-on-mainnet)
* The routes you want to protect.
* Your receiving wallet address.
<Tabs>
<Tab title="Express">
Full example in the repo [here](https://github.com/coinbase/x402/tree/main/examples/typescript/servers/express).
```typescript
import express from "express";
import { paymentMiddleware } from "@x402/express";
import { x402ResourceServer, HTTPFacilitatorClient } from "@x402/core/server";
import { registerExactEvmScheme } from "@x402/evm/exact/server";
const app = express();
// Your receiving wallet address
const payTo = "0xYourAddress";
// Create facilitator client (testnet)
const facilitatorClient = new HTTPFacilitatorClient({
url: "https://x402.org/facilitator"
});
// Create resource server and register EVM scheme
const server = new x402ResourceServer(facilitatorClient);
registerExactEvmScheme(server);
app.use(
paymentMiddleware(
{
"GET /weather": {
accepts: [
{
scheme: "exact",
price: "$0.001", // USDC amount in dollars
network: "eip155:84532", // Base Sepolia (CAIP-2 format)
payTo,
},
],
description: "Get current weather data for any location",
mimeType: "application/json",
},
},
server,
),
);
// Implement your route
app.get("/weather", (req, res) => {
res.send({
report: {
weather: "sunny",
temperature: 70,
},
});
});
app.listen(4021, () => {
console.log(`Server listening at http://localhost:4021`);
});
```
</Tab>
<Tab title="Next.js">
Full example in the repo [here](https://github.com/coinbase/x402/tree/main/examples/typescript/fullstack/next).
```typescript
// middleware.ts
import { paymentProxy } from "@x402/next";
import { x402ResourceServer, HTTPFacilitatorClient } from "@x402/core/server";
import { registerExactEvmScheme } from "@x402/evm/exact/server";
const payTo = "0xYourAddress";
const facilitatorClient = new HTTPFacilitatorClient({
url: "https://x402.org/facilitator"
});
const server = new x402ResourceServer(facilitatorClient);
registerExactEvmScheme(server);
export const middleware = paymentProxy(
{
"/api/protected": {
accepts: [
{
scheme: "exact",
price: "$0.01",
network: "eip155:84532",
payTo,
},
],
description: "Access to protected content",
mimeType: "application/json",
},
},
server,
);
export const config = {
matcher: ["/api/protected/:path*"],
};
```
</Tab>
<Tab title="Hono">
Full example in the repo [here](https://github.com/coinbase/x402/tree/main/examples/typescript/servers/hono).
```typescript
import { Hono } from "hono";
import { serve } from "@hono/node-server";
import { paymentMiddleware } from "@x402/hono";
import { x402ResourceServer, HTTPFacilitatorClient } from "@x402/core/server";
import { registerExactEvmScheme } from "@x402/evm/exact/server";
const app = new Hono();
const payTo = "0xYourAddress";
const facilitatorClient = new HTTPFacilitatorClient({
url: "https://x402.org/facilitator"
});
const server = new x402ResourceServer(facilitatorClient);
registerExactEvmScheme(server);
app.use(
paymentMiddleware(
{
"/protected-route": {
accepts: [
{
scheme: "exact",
price: "$0.10",
network: "eip155:84532",
payTo,
},
],
description: "Access to premium content",
mimeType: "application/json",
},
},
server,
),
);
app.get("/protected-route", (c) => {
return c.json({ message: "This content is behind a paywall" });
});
serve({ fetch: app.fetch, port: 3000 });
```
</Tab>
<Tab title="Go (Gin)">
Full example in the repo [here](https://github.com/coinbase/x402/tree/main/examples/go/servers/gin).
```go
package main
import (
"net/http"
"time"
x402 "github.com/coinbase/x402/go"
x402http "github.com/coinbase/x402/go/http"
ginmw "github.com/coinbase/x402/go/http/gin"
evm "github.com/coinbase/x402/go/mechanisms/evm/exact/server"
"github.com/gin-gonic/gin"
)
func main() {
payTo := "0xYourAddress"
network := x402.Network("eip155:84532") // Base Sepolia (CAIP-2 format)
r := gin.Default()
// Create facilitator client
facilitatorClient := x402http.NewHTTPFacilitatorClient(&x402http.FacilitatorConfig{
URL: "https://x402.org/facilitator",
})
// Apply x402 payment middleware
r.Use(ginmw.X402Payment(ginmw.Config{
Routes: x402http.RoutesConfig{
"GET /weather": {
Accepts: x402http.PaymentOptions{
{
Scheme: "exact",
PayTo: payTo,
Price: "$0.001",
Network: network,
},
},
Description: "Get weather data for a city",
MimeType: "application/json",
},
},
Facilitator: facilitatorClient,
Schemes: []ginmw.SchemeConfig{
{Network: network, Server: evm.NewExactEvmScheme()},
},
SyncFacilitatorOnStart: true,
Timeout: 30 * time.Second,
}))
// Protected endpoint
r.GET("/weather", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"weather": "sunny",
"temperature": 70,
})
})
r.Run(":4021")
}
```
</Tab>
<Tab title="FastAPI">
Full example in the repo [here](https://github.com/coinbase/x402/tree/main/examples/python/servers/fastapi).
```python
from typing import Any
from fastapi import FastAPI
from x402.http import FacilitatorConfig, HTTPFacilitatorClient, PaymentOption
from x402.http.middleware.fastapi import PaymentMiddlewareASGI
from x402.http.types import RouteConfig
from x402.mechanisms.evm.exact import ExactEvmServerScheme
from x402.server import x402ResourceServer
app = FastAPI()
# Your receiving wallet address
pay_to = "0xYourAddress"
# Create facilitator client (testnet)
facilitator = HTTPFacilitatorClient(
FacilitatorConfig(url="https://x402.org/facilitator")
)
# Create resource server and register EVM scheme
server = x402ResourceServer(facilitator)
server.register("eip155:84532", ExactEvmServerScheme())
# Define protected routes
routes: dict[str, RouteConfig] = {
"GET /weather": RouteConfig(
accepts=[
PaymentOption(
scheme="exact",
pay_to=pay_to,
price="$0.001", # USDC amount in dollars
network="eip155:84532", # Base Sepolia (CAIP-2 format)
),
],
mime_type="application/json",
description="Get current weather data for any location",
),
}
# Add payment middleware
app.add_middleware(PaymentMiddlewareASGI, routes=routes, server=server)
@app.get("/weather")
async def get_weather() -> dict[str, Any]:
return {
"report": {
"weather": "sunny",
"temperature": 70,
}
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=4021)
```
</Tab>
<Tab title="Flask">
Full example in the repo [here](https://github.com/coinbase/x402/tree/main/examples/python/servers/flask).
```python
from flask import Flask, jsonify
from x402.http import FacilitatorConfig, HTTPFacilitatorClientSync, PaymentOption
from x402.http.middleware.flask import payment_middleware
from x402.http.types import RouteConfig
from x402.mechanisms.evm.exact import ExactEvmServerScheme
from x402.server import x402ResourceServerSync
app = Flask(__name__)
pay_to = "0xYourAddress"
facilitator = HTTPFacilitatorClientSync(
FacilitatorConfig(url="https://x402.org/facilitator")
)
server = x402ResourceServerSync(facilitator)
server.register("eip155:84532", ExactEvmServerScheme())
routes: dict[str, RouteConfig] = {
"GET /weather": RouteConfig(
accepts=[
PaymentOption(
scheme="exact",
pay_to=pay_to,
price="$0.001",
network="eip155:84532",
),
],
mime_type="application/json",
description="Get current weather data for any location",
),
}
payment_middleware(app, routes=routes, server=server)
@app.route("/weather")
def get_weather():
return jsonify({
"report": {
"weather": "sunny",
"temperature": 70,
}
})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=4021)
```
</Tab>
</Tabs>
**Route Configuration Interface:**
```typescript
interface RouteConfig {
accepts: Array<{
scheme: string; // Payment scheme (e.g., "exact")
price: string; // Price in dollars (e.g., "$0.01")
network: string; // Network in CAIP-2 format (e.g., "eip155:84532")
payTo: string; // Your wallet address
}>;
description?: string; // Description of the resource
mimeType?: string; // MIME type of the response
extensions?: object; // Optional extensions (e.g., Bazaar)
}
```
When a request is made to these routes without payment, your server will respond with the HTTP 402 Payment Required code and payment instructions.
### 3. Test Your Integration
To verify:
1. Make a request to your endpoint (e.g., `curl http://localhost:4021/weather`).
2. The server responds with a 402 Payment Required, including payment instructions in the `PAYMENT-REQUIRED` header.
3. 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](/getting-started/quickstart-for-buyers).
4. Retry the request, this time including the `PAYMENT-SIGNATURE` header containing the cryptographic proof of payment.
5. The server verifies the payment via the facilitator and, if valid, returns your actual API response (e.g., `{ "data": "Your paid API response." }`).
### 4. Enhance Discovery with Metadata (Recommended)
When using a facilitator that supports the Bazaar extension, your endpoints can be listed in the [x402 Bazaar](/core-concepts/bazaar-discovery-layer), our discovery layer that helps buyers and AI agents find services. To enable discovery:
```typescript
{
"GET /weather": {
accepts: [
{
scheme: "exact",
price: "$0.001",
network: "eip155:8453",
payTo: "0xYourAddress",
},
],
description: "Get real-time weather data including temperature, conditions, and humidity",
mimeType: "application/json",
extensions: {
bazaar: {
discoverable: true,
category: "weather",
tags: ["forecast", "real-time"],
},
},
},
}
```
Learn more about the discovery layer in the [Bazaar documentation](/core-concepts/bazaar-discovery-layer).
### 5. Error Handling
* If you run into trouble, check out the examples in the [repo](https://github.com/coinbase/x402/tree/main/examples) for more context and full code.
* Run `npm install` or `go mod tidy` to install dependencies
---
## Running on Mainnet
Once you've tested your integration on testnet, you're ready to accept real payments on mainnet.
### 1. Update the Facilitator URL
For mainnet, use a production facilitator. See the [x402 Ecosystem](https://www.x402.org/ecosystem?category=facilitators) for available options. Example using one facilitator:
<Tabs>
<Tab title="Node.js">
```typescript
const facilitatorClient = new HTTPFacilitatorClient({
url: "https://api.cdp.coinbase.com/platform/v2/x402"
});
```
</Tab>
<Tab title="Go">
```go
facilitatorClient := x402http.NewHTTPFacilitatorClient(&x402http.FacilitatorConfig{
URL: "https://api.cdp.coinbase.com/platform/v2/x402",
})
```
</Tab>
<Tab title="Python (FastAPI)">
```python
from x402.http import FacilitatorConfig, HTTPFacilitatorClient
facilitator = HTTPFacilitatorClient(
FacilitatorConfig(url="https://api.cdp.coinbase.com/platform/v2/x402")
)
```
</Tab>
<Tab title="Python (Flask)">
```python
from x402.http import FacilitatorConfig, HTTPFacilitatorClientSync
facilitator = HTTPFacilitatorClientSync(
FacilitatorConfig(url="https://api.cdp.coinbase.com/platform/v2/x402")
)
```
</Tab>
</Tabs>
### 2. Update Your Network Identifier
Change from testnet to mainnet network identifiers:
<Tabs>
<Tab title="Base Mainnet">
```typescript
// Testnet → Mainnet
network: "eip155:8453", // Base mainnet (was eip155:84532)
```
</Tab>
<Tab title="Solana Mainnet">
```typescript
// Testnet → Mainnet
network: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp", // Solana mainnet
// For Solana, use a Solana wallet address (base58 format)
payTo: "YourSolanaWalletAddress",
```
</Tab>
<Tab title="Multi-Network">
```typescript
// Support multiple networks on the same endpoint
{
"GET /weather": {
accepts: [
{
scheme: "exact",
price: "$0.001",
network: "eip155:8453", // Base mainnet
payTo: "0xYourEvmAddress",
},
{
scheme: "exact",
price: "$0.001",
network: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp", // Solana mainnet
payTo: "YourSolanaAddress",
},
],
description: "Weather data",
},
}
```
</Tab>
</Tabs>
### 3. Register Multiple Schemes (Multi-Network)
For multi-network support, register both EVM and SVM schemes:
<Tabs>
<Tab title="Node.js">
```typescript
import { registerExactEvmScheme } from "@x402/evm/exact/server";
import { registerExactSvmScheme } from "@x402/svm/exact/server";
const server = new x402ResourceServer(facilitatorClient);
registerExactEvmScheme(server);
registerExactSvmScheme(server);
```
</Tab>
<Tab title="Go">
```go
import (
evm "github.com/coinbase/x402/go/mechanisms/evm/exact/server"
svm "github.com/coinbase/x402/go/mechanisms/svm/exact/server"
)
r.Use(ginmw.X402Payment(ginmw.Config{
// ...
Schemes: []ginmw.SchemeConfig{
{Network: x402.Network("eip155:8453"), Server: evm.NewExactEvmScheme()},
{Network: x402.Network("solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"), Server: svm.NewExactSvmScheme()},
},
}))
```
</Tab>
<Tab title="Python">
```python
from x402.mechanisms.evm.exact import ExactEvmServerScheme
from x402.mechanisms.svm.exact import ExactSvmServerScheme
from x402.server import x402ResourceServer
server = x402ResourceServer(facilitator)
server.register("eip155:8453", ExactEvmServerScheme()) # Base mainnet
server.register("solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp", ExactSvmServerScheme()) # Solana mainnet
```
</Tab>
</Tabs>
### 4. Update Your Wallet
Make sure your receiving wallet address is a real mainnet address where you want to receive USDC payments.
### 5. Test with Real Payments
Before going live:
1. Test with small amounts first
2. Verify payments are arriving in your wallet
3. Monitor the facilitator for any issues
**Warning:** Mainnet transactions involve real money. Always test thoroughly on testnet first and start with small amounts on mainnet.
---
## Network Identifiers (CAIP-2)
x402 v2 uses [CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md) format for network identifiers:
| Network | CAIP-2 Identifier |
|---------|-------------------|
| Base Mainnet | `eip155:8453` |
| Base Sepolia | `eip155:84532` |
| Solana Mainnet | `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` |
| Solana Devnet | `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` |
See [Network Support](/core-concepts/network-and-token-support) for the full list.
---
### Next Steps
* Looking for something more advanced? Check out the [Advanced Example](https://github.com/coinbase/x402/tree/main/examples/typescript/servers/advanced)
* Get started as a [buyer](/getting-started/quickstart-for-buyers)
* Learn about the [Bazaar discovery layer](/core-concepts/bazaar-discovery-layer)
For questions or support, join our [Discord](https://discord.gg/cdp).
### Summary
This quickstart covered:
* Installing the x402 SDK and relevant middleware
* Adding payment middleware to your API and configuring it
* Testing your integration
* Deploying to mainnet with CAIP-2 network identifiers
Your API is now ready to accept crypto payments through x402.