Loading...
Loading...
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 middleware
npx skill4agent add aznatkoiny/zai-skills x402-payments402PAYMENT-REQUIREDPAYMENT-SIGNATUREPOST /verifyPOST /settle200PAYMENT-RESPONSEhttps://x402.org/facilitatorexactuptodeferredeip155:84532eip155:8453solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1TransferWithAuthorizationnpm install @x402/express @x402/core @x402/evmimport 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"));npm install @x402/fetch @x402/core @x402/evm viemimport { 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 | Choice | Packages |
|---|---|---|
| Server: Express | | |
| Server: Next.js | | |
| Server: Hono | | |
| Client: fetch | | |
| Client: axios | | |
| Client: manual | | |
| Chain: EVM | | |
| Chain: Solana | | |
| Chain: both | Register both schemes on same client/server | All chain deps |
| Env: testing | Facilitator | Base Sepolia / Solana Devnet |
| Env: production | CDP facilitator + API keys | Base Mainnet / Solana Mainnet |
| Agent: MCP | MCP server with | See |
| Agent: Anthropic | Tool-use with | See |
| Task | Read this file |
|---|---|
| Headers, payloads, CAIP-2 IDs, facilitator API, V1→V2 changes | |
| Express / Hono / Next.js middleware, multi-route, dynamic pricing | |
| Fetch / axios client, wallet setup, lifecycle hooks, error handling | |
| AI agent payments, MCP server, tool discovery, budget controls | |
| Testnet→mainnet migration, CDP keys, faucets, security, sessions | |
registerExactEvmScheme(server)registerExactEvmScheme(client, { signer })server.register("eip155:84532", new ExactEvmScheme())PAYMENT-REQUIREDPAYMENT-SIGNATUREPAYMENT-RESPONSEX-PAYMENTX-PAYMENT-RESPONSE"$0.001"https://github.com/coinbase/x402examples/typescript/https://docs.cdp.coinbase.com/x402/welcomehttps://x402.gitbook.io/x402