x402 Protocol Skill
Facts current as of July 2026 — verify pricing and model IDs against https://docs.claude.com, and protocol/package details against the x402 docs.
Protocol Overview
x402 embeds stablecoin payments into HTTP by using the 402 "Payment Required" status code. A server responds with payment requirements; the client signs a payment authorization, resubmits the request, and gets the resource after verification and settlement.
Payment flow:
- Client sends HTTP request → Server returns
402 + PAYMENT-REQUIRED header (base64 JSON)
- Client reads requirements, creates signed payment payload
- Client resubmits request with
PAYMENT-SIGNATURE header (base64 JSON)
- Server verifies payment via facilitator
POST /verify
- Server performs work, settles via facilitator
POST /settle
- Server returns
200 + resource + PAYMENT-RESPONSE header (contains txHash)
Key concepts:
- Facilitators verify and settle payments without holding funds. Use
https://x402.org/facilitator for testnet, CDP facilitator for mainnet.
- Schemes:
exact (fixed price per request) is the production scheme. upto and deferred are proposed.
- Networks: Identified by CAIP-2 format —
eip155:84532 (Base Sepolia), eip155:8453 (Base Mainnet), solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1 (Solana Devnet).
- EVM uses EIP-3009 gasless
TransferWithAuthorization. Solana uses SPL token transfers.
Quick-Start: Protect an API Endpoint (Seller)
npm install @x402/express @x402/core @x402/evm
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();
const payTo = process.env.PAY_TO!;
const facilitatorClient = new HTTPFacilitatorClient({
url: "https://x402.org/facilitator",
});
const server = new x402ResourceServer(facilitatorClient);
registerExactEvmScheme(server);
app.use(
paymentMiddleware(
{
"GET /weather": {
accepts: [
{ scheme: "exact", price: "$0.001", network: "eip155:84532", payTo },
],
description: "Get current weather data",
mimeType: "application/json",
},
},
server,
),
);
app.get("/weather", (req, res) => {
res.json({ weather: "sunny", temperature: 70 });
});
app.listen(4021, () => console.log("Server on :4021"));
Quick-Start: Pay for x402 Resources (Buyer/Agent)
npm install @x402/fetch @x402/core @x402/evm viem
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client, x402HTTPClient } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
const client = new x402Client();
registerExactEvmScheme(client, { signer });
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
const response = await fetchWithPayment("http://localhost:4021/weather");
const data = await response.json();
console.log(data);
// Read payment receipt
const httpClient = new x402HTTPClient(client);
const receipt = httpClient.getPaymentSettleResponse(
(name) => response.headers.get(name),
);
console.log("Tx:", receipt?.txHash);
Decision Tree
| Decision |
Choice |
Packages |
| Server: Express |
paymentMiddleware from @x402/express |
@x402/express @x402/core @x402/evm |
| Server: Next.js |
paymentProxy from @x402/next |
@x402/next @x402/core @x402/evm |
| Server: Hono |
paymentMiddleware from @x402/hono |
@x402/hono @x402/core @x402/evm |
| Client: fetch |
wrapFetchWithPayment |
@x402/fetch @x402/core @x402/evm viem |
| Client: axios |
wrapAxiosWithPayment |
@x402/axios @x402/core @x402/evm viem axios |
| Client: manual |
x402Client + x402HTTPClient from @x402/core |
@x402/core @x402/evm viem |
| Chain: EVM |
registerExactEvmScheme |
@x402/evm + viem |
| Chain: Solana |
registerExactSvmScheme |
@x402/svm + @solana/kit @scure/base |
| Chain: both |
Register both schemes on same client/server |
All chain deps |
| Env: testing |
Facilitator https://x402.org/facilitator |
Base Sepolia / Solana Devnet |
| Env: production |
CDP facilitator + API keys |
Base Mainnet / Solana Mainnet |
| Agent: MCP |
MCP server with @x402/axios |
See references/agentic-patterns.md |
| Agent: Anthropic |
Tool-use with @x402/fetch |
See references/agentic-patterns.md |
Reference File Navigation
| Task |
Read this file |
| Headers, payloads, CAIP-2 IDs, facilitator API, V1→V2 changes |
references/protocol-spec.md |
| Express / Hono / Next.js middleware, multi-route, dynamic pricing |
references/server-patterns.md |
| Fetch / axios client, wallet setup, lifecycle hooks, error handling |
references/client-patterns.md |
| AI agent payments, MCP server, tool discovery, budget controls |
references/agentic-patterns.md |
| Testnet→mainnet migration, CDP keys, faucets, security, sessions |
references/deployment.md |
Critical Implementation Notes
- Register schemes before wrapping fetch/axios — order matters.
- Two equivalent registration APIs:
- Function:
registerExactEvmScheme(server) / registerExactEvmScheme(client, { signer })
- Method:
server.register("eip155:84532", new ExactEvmScheme())
- V2 headers (current):
PAYMENT-REQUIRED, PAYMENT-SIGNATURE, PAYMENT-RESPONSE.
V1 headers (legacy): X-PAYMENT, X-PAYMENT-RESPONSE. SDK is backward-compatible.
- Price format:
"$0.001" (dollar string) — SDK converts to atomic units (6 decimals for USDC).
- Python SDK uses V1 patterns only. Use TypeScript or Go for V2.
- Node.js v24+ required for the TypeScript SDK.
- Repo:
https://github.com/coinbase/x402 — canonical examples in examples/typescript/.
- Docs:
https://docs.cdp.coinbase.com/x402/welcome and https://x402.gitbook.io/x402.
1---2name: x402-payments3description: Build applications using the x402 protocol — Coinbase's open standard for HTTP-native stablecoin payments using the HTTP 402 status code. Use this skill when: - Creating APIs that require USDC payments per request (seller/server side) - Building clients or AI agents that pay for x402-protected resources (buyer/client side) - Implementing MCP servers with paid tools for Claude Desktop - Adding payment middleware to Express, Hono, or Next.js applications - Working with Base (EVM) or Solana (SVM) payment flows - Building machine-to-machine or agent-to-agent payment systems - Integrating micropayments, pay-per-use billing, or paid API access Triggers: x402, HTTP 402, payment required, USDC payments, micropayments, pay-per-use API, agentic payments, stablecoin payments, paid API endpoint, paywall middleware4---56# x402 Protocol Skill78> Facts current as of July 2026 — verify pricing and model IDs against https://docs.claude.com, and protocol/package details against the x402 docs.910## Protocol Overview1112x402 embeds stablecoin payments into HTTP by using the 402 "Payment Required" status code. A server responds with payment requirements; the client signs a payment authorization, resubmits the request, and gets the resource after verification and settlement.1314**Payment flow:**151. Client sends HTTP request → Server returns `402` + `PAYMENT-REQUIRED` header (base64 JSON)162. Client reads requirements, creates signed payment payload173. Client resubmits request with `PAYMENT-SIGNATURE` header (base64 JSON)184. Server verifies payment via facilitator `POST /verify`195. Server performs work, settles via facilitator `POST /settle`206. Server returns `200` + resource + `PAYMENT-RESPONSE` header (contains txHash)2122**Key concepts:**23- **Facilitators** verify and settle payments without holding funds. Use `https://x402.org/facilitator` for testnet, CDP facilitator for mainnet.24- **Schemes**: `exact` (fixed price per request) is the production scheme. `upto` and `deferred` are proposed.25- **Networks**: Identified by CAIP-2 format — `eip155:84532` (Base Sepolia), `eip155:8453` (Base Mainnet), `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` (Solana Devnet).26- **EVM** uses EIP-3009 gasless `TransferWithAuthorization`. **Solana** uses SPL token transfers.2728## Quick-Start: Protect an API Endpoint (Seller)2930```bash31npm install @x402/express @x402/core @x402/evm32```3334```typescript35import express from "express";36import { paymentMiddleware } from "@x402/express";37import { x402ResourceServer, HTTPFacilitatorClient } from "@x402/core/server";38import { registerExactEvmScheme } from "@x402/evm/exact/server";3940const app = express();41const payTo = process.env.PAY_TO!;4243const facilitatorClient = new HTTPFacilitatorClient({44 url: "https://x402.org/facilitator",45});46const server = new x402ResourceServer(facilitatorClient);47registerExactEvmScheme(server);4849app.use(50 paymentMiddleware(51 {52 "GET /weather": {53 accepts: [54 { scheme: "exact", price: "$0.001", network: "eip155:84532", payTo },55 ],56 description: "Get current weather data",57 mimeType: "application/json",58 },59 },60 server,61 ),62);6364app.get("/weather", (req, res) => {65 res.json({ weather: "sunny", temperature: 70 });66});6768app.listen(4021, () => console.log("Server on :4021"));69```7071## Quick-Start: Pay for x402 Resources (Buyer/Agent)7273```bash74npm install @x402/fetch @x402/core @x402/evm viem75```7677```typescript78import { wrapFetchWithPayment } from "@x402/fetch";79import { x402Client, x402HTTPClient } from "@x402/core/client";80import { registerExactEvmScheme } from "@x402/evm/exact/client";81import { privateKeyToAccount } from "viem/accounts";8283const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);84const client = new x402Client();85registerExactEvmScheme(client, { signer });8687const fetchWithPayment = wrapFetchWithPayment(fetch, client);8889const response = await fetchWithPayment("http://localhost:4021/weather");90const data = await response.json();91console.log(data);9293// Read payment receipt94const httpClient = new x402HTTPClient(client);95const receipt = httpClient.getPaymentSettleResponse(96 (name) => response.headers.get(name),97);98console.log("Tx:", receipt?.txHash);99```100101## Decision Tree102103| Decision | Choice | Packages |104|----------|--------|----------|105| **Server: Express** | `paymentMiddleware` from `@x402/express` | `@x402/express @x402/core @x402/evm` |106| **Server: Next.js** | `paymentProxy` from `@x402/next` | `@x402/next @x402/core @x402/evm` |107| **Server: Hono** | `paymentMiddleware` from `@x402/hono` | `@x402/hono @x402/core @x402/evm` |108| **Client: fetch** | `wrapFetchWithPayment` | `@x402/fetch @x402/core @x402/evm viem` |109| **Client: axios** | `wrapAxiosWithPayment` | `@x402/axios @x402/core @x402/evm viem axios` |110| **Client: manual** | `x402Client` + `x402HTTPClient` from `@x402/core` | `@x402/core @x402/evm viem` |111| **Chain: EVM** | `registerExactEvmScheme` | `@x402/evm` + `viem` |112| **Chain: Solana** | `registerExactSvmScheme` | `@x402/svm` + `@solana/kit @scure/base` |113| **Chain: both** | Register both schemes on same client/server | All chain deps |114| **Env: testing** | Facilitator `https://x402.org/facilitator` | Base Sepolia / Solana Devnet |115| **Env: production** | CDP facilitator + API keys | Base Mainnet / Solana Mainnet |116| **Agent: MCP** | MCP server with `@x402/axios` | See `references/agentic-patterns.md` |117| **Agent: Anthropic** | Tool-use with `@x402/fetch` | See `references/agentic-patterns.md` |118119## Reference File Navigation120121| Task | Read this file |122|------|---------------|123| Headers, payloads, CAIP-2 IDs, facilitator API, V1→V2 changes | `references/protocol-spec.md` |124| Express / Hono / Next.js middleware, multi-route, dynamic pricing | `references/server-patterns.md` |125| Fetch / axios client, wallet setup, lifecycle hooks, error handling | `references/client-patterns.md` |126| AI agent payments, MCP server, tool discovery, budget controls | `references/agentic-patterns.md` |127| Testnet→mainnet migration, CDP keys, faucets, security, sessions | `references/deployment.md` |128129## Critical Implementation Notes1301311. **Register schemes before wrapping** fetch/axios — order matters.1322. **Two equivalent registration APIs**:133 - Function: `registerExactEvmScheme(server)` / `registerExactEvmScheme(client, { signer })`134 - Method: `server.register("eip155:84532", new ExactEvmScheme())`1353. **V2 headers** (current): `PAYMENT-REQUIRED`, `PAYMENT-SIGNATURE`, `PAYMENT-RESPONSE`.136 V1 headers (legacy): `X-PAYMENT`, `X-PAYMENT-RESPONSE`. SDK is backward-compatible.1374. **Price format**: `"$0.001"` (dollar string) — SDK converts to atomic units (6 decimals for USDC).1385. **Python SDK** uses V1 patterns only. Use TypeScript or Go for V2.1396. **Node.js v24+** required for the TypeScript SDK.1407. **Repo**: `https://github.com/coinbase/x402` — canonical examples in `examples/typescript/`.1418. **Docs**: `https://docs.cdp.coinbase.com/x402/welcome` and `https://x402.gitbook.io/x402`.