Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aznatkoiny avatar

X402 Payments

  • 16 installs
  • 9 repo stars
  • Updated August 4, 2026
  • aznatkoiny/zai-skills

x402-payments is a Claude skill for building applications with Coinbase's x402 protocol, which embeds USDC stablecoin payments into HTTP using the 402 status code.

About

x402-payments is a skill for building applications with Coinbase's x402 protocol, an open standard for HTTP-native stablecoin payments that uses the HTTP 402 status code. A developer uses it to add USDC pay-per-request billing to an API, or to build clients and AI agents that pay for x402-protected resources. It covers server middleware for Express, Hono, and Next.js, buyer-side fetch and axios clients, and both Base (EVM) and Solana payment flows.

  • Implements Coinbase's x402 protocol for HTTP-native USDC stablecoin payments via the 402 status code
  • Provides seller-side payment middleware for Express, Hono, and Next.js plus buyer-side fetch/axios clients
  • Supports both Base (EVM, EIP-3009) and Solana (SVM, SPL) payment flows with testnet and mainnet facilitators

X402 Payments by the numbers

  • 16 all-time installs (skills.sh)
  • Ranked #274 of 479 Web3 & Blockchain skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
At a glance

x402-payments capabilities & compatibility

Free on testnet (x402.org facilitator, Base Sepolia); mainnet needs CDP facilitator API keys plus USDC and gas.

Capabilities
payment middleware · stablecoin checkout · agent payments
Works with
stripe
Use cases
api development
Pricing
Bring your own API key
From the docs

What x402-payments says it does

x402 embeds stablecoin payments into HTTP by using the 402 "Payment Required" status code.
SKILL.md
npx skills add https://github.com/aznatkoiny/zai-skills --skill x402-payments

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs16
repo stars9
Last updatedAugust 4, 2026
Repositoryaznatkoiny/zai-skills

What it does

Add per-request USDC stablecoin payments to an API or build agents that pay for x402-protected resources.

Who is it for?

Adding pay-per-request USDC billing to an API, or building AI agents and clients that pay for x402-protected resources.

Skip if: Traditional card checkout, fiat subscriptions, or payment flows that do not involve stablecoins on Base or Solana.

When should I use this skill?

Creating APIs that require USDC payments per request, or building buyers or agents that pay for x402-protected resources.

What you get

An API endpoint gated by a signed USDC payment, or a client that automatically pays and retrieves x402-protected resources.

  • payment-gated API endpoints
  • x402 buyer client wrappers for fetch or axios

By the numbers

  • 6-step payment flow (request, 402, sign, resubmit, verify, settle)
  • supports 3 server frameworks: Express, Hono, Next.js

Files

SKILL.mdMarkdownGitHub ↗

x402 Protocol Skill

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: 1. Client sends HTTP request → Server returns 402 + PAYMENT-REQUIRED header (base64 JSON) 2. Client reads requirements, creates signed payment payload 3. Client resubmits request with PAYMENT-SIGNATURE header (base64 JSON) 4. Server verifies payment via facilitator POST /verify 5. Server performs work, settles via facilitator POST /settle 6. 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

DecisionChoicePackages
Server: ExpresspaymentMiddleware from @x402/express@x402/express @x402/core @x402/evm
Server: Next.jspaymentProxy from @x402/next@x402/next @x402/core @x402/evm
Server: HonopaymentMiddleware from @x402/hono@x402/hono @x402/core @x402/evm
Client: fetchwrapFetchWithPayment@x402/fetch @x402/core @x402/evm viem
Client: axioswrapAxiosWithPayment@x402/axios @x402/core @x402/evm viem axios
Client: manualx402Client + x402HTTPClient from @x402/core@x402/core @x402/evm viem
Chain: EVMregisterExactEvmScheme@x402/evm + viem
Chain: SolanaregisterExactSvmScheme@x402/svm + @solana/kit @scure/base
Chain: bothRegister both schemes on same client/serverAll chain deps
Env: testingFacilitator https://x402.org/facilitatorBase Sepolia / Solana Devnet
Env: productionCDP facilitator + API keysBase Mainnet / Solana Mainnet
Agent: MCPMCP server with @x402/axiosSee references/agentic-patterns.md
Agent: AnthropicTool-use with @x402/fetchSee references/agentic-patterns.md

Reference File Navigation

TaskRead this file
Headers, payloads, CAIP-2 IDs, facilitator API, V1→V2 changesreferences/protocol-spec.md
Express / Hono / Next.js middleware, multi-route, dynamic pricingreferences/server-patterns.md
Fetch / axios client, wallet setup, lifecycle hooks, error handlingreferences/client-patterns.md
AI agent payments, MCP server, tool discovery, budget controlsreferences/agentic-patterns.md
Testnet→mainnet migration, CDP keys, faucets, security, sessionsreferences/deployment.md

Critical Implementation Notes

1. Register schemes before wrapping fetch/axios — order matters. 2. Two equivalent registration APIs:

  • Function: registerExactEvmScheme(server) / registerExactEvmScheme(client, { signer })
  • Method: server.register("eip155:84532", new ExactEvmScheme())

3. V2 headers (current): PAYMENT-REQUIRED, PAYMENT-SIGNATURE, PAYMENT-RESPONSE. V1 headers (legacy): X-PAYMENT, X-PAYMENT-RESPONSE. SDK is backward-compatible. 4. Price format: "$0.001" (dollar string) — SDK converts to atomic units (6 decimals for USDC). 5. Python SDK uses V1 patterns only. Use TypeScript or Go for V2. 6. Node.js v24+ required for the TypeScript SDK. 7. Repo: https://github.com/coinbase/x402 — canonical examples in examples/typescript/. 8. Docs: https://docs.cdp.coinbase.com/x402/welcome and https://x402.gitbook.io/x402.

Related skills

FAQ

Which frameworks does x402-payments support on the server side?

It provides payment middleware for Express, Hono, and Next.js, using paymentMiddleware for Express and Hono and paymentProxy for Next.js.

Which blockchains does x402-payments work with?

It supports Base (EVM) using EIP-3009 gasless TransferWithAuthorization and Solana (SVM) using SPL token transfers.

Web3 & Blockchainpaymentsecommerce

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.