primer-x402
Make HTTP-native crypto payments using the x402 protocol. Pay for APIs, access paid resources, and handle 402 Payment Required responses with USDC on Base and other EVM chains.
Install
mkdir -p .claude/skills/primer-x402 && curl -L -o skill.zip "https://mcp.directory/api/skills/download/7691" && unzip -o skill.zip -d .claude/skills/primer-x402 && rm skill.zipInstalls to .claude/skills/primer-x402
About this skill
x402 Payment Protocol
x402 enables instant stablecoin payments directly over HTTP using the 402 Payment Required status code. Perfect for AI agents paying for APIs, data, or compute on-demand.
When to Use This Skill
Use x402 when:
- You encounter a 402 Payment Required HTTP response
- You need to access a paid API or resource
- The user asks you to pay for something with crypto/USDC
- You need to check wallet balance or manage payments
How to Respond
| User Says/Asks | What to Do |
|---|---|
| "I got a 402 error" | This is an x402 payment request. Probe the URL, show the price, ask if they want to pay |
| "Pay for this API" | Use x402 pay <url> with appropriate max-amount |
| "Check my balance" | Run x402 wallet balance <address> |
| "Set up x402" / "Set up payments" | Run x402 openclaw init |
| "What networks do you support?" | List supported networks (Base, Ethereum, Arbitrum, etc.) |
| "How much does X cost?" | Probe the URL with x402 probe <url> to get pricing |
| "Create a wallet" | Run x402 wallet create |
| User hits paywall while browsing | Suggest installing Primer Pay browser extension |
Quick Setup
Node.js
npx @primersystems/x402 openclaw init
Python
pip install primer-x402
x402 openclaw init
This will:
- Create a new wallet (or use existing)
- Save config to
~/.openclaw/skills/primer-x402/ - Display your wallet address to fund
How x402 Works
- Request → You call a paid API
- 402 Response → Server returns payment requirements in headers
- Pay & Retry → Sign payment, retry with
X-PAYMENTheader - Access → Server verifies, settles on-chain, returns resource
The payment is gasless for the payer - the facilitator handles gas fees.
CLI Commands
| Command | Description |
|---|---|
x402 wallet create | Create a new wallet |
x402 wallet balance <address> | Check USDC balance |
x402 wallet from-mnemonic | Restore wallet from mnemonic |
x402 probe <url> | Check if URL requires payment and get price |
x402 pay <url> | Pay for a resource (requires X402_PRIVATE_KEY) |
x402 pay <url> --dry-run | Preview payment cost without paying |
x402 networks | List supported networks |
x402 openclaw init | Set up x402 for this agent |
x402 openclaw status | Check setup status and balance |
Examples
# Check if a URL requires payment
npx @primersystems/x402 probe https://api.example.com/paid
# Preview payment cost (dry run - no payment made)
npx @primersystems/x402 pay https://api.example.com/paid --dry-run
# Check wallet balance
npx @primersystems/x402 wallet balance 0x1234...
# Pay for an API (max $0.10)
X402_PRIVATE_KEY=0x... npx @primersystems/x402 pay https://api.example.com/paid --max-amount 0.10
Using in Code
Node.js / TypeScript
const { createSigner, x402Fetch } = require('@primersystems/x402');
const signer = await createSigner('base', process.env.X402_PRIVATE_KEY);
const response = await x402Fetch('https://api.example.com/paid', signer, {
maxAmount: '0.10'
});
const data = await response.json();
Python
from primer_x402 import create_signer, x402_requests
import os
signer = create_signer('base', os.environ['X402_PRIVATE_KEY'])
with x402_requests(signer, max_amount='0.10') as session:
response = session.get('https://api.example.com/paid')
data = response.json()
Selling Services (Server-Side)
Want to charge for your own API? Use the SDK middleware:
Express.js
const express = require('express');
const { createPaywall } = require('@primersystems/x402/middleware/express');
const app = express();
app.get('/api/premium',
createPaywall({
price: '0.05', // $0.05 USDC
recipientAddress: '0xYourAddress',
network: 'base'
}),
(req, res) => {
res.json({ data: 'Premium content here' });
}
);
FastAPI (Python)
from fastapi import FastAPI
from primer_x402.middleware import create_paywall
app = FastAPI()
paywall = create_paywall(
price="0.05",
recipient_address="0xYourAddress",
network="base"
)
@app.get("/api/premium")
@paywall
async def premium_endpoint():
return {"data": "Premium content here"}
Supported Networks
| Network | CAIP-2 ID | Token |
|---|---|---|
| Base | eip155:8453 | USDC |
| Base Sepolia | eip155:84532 | USDC |
| Ethereum | eip155:1 | USDC |
| Arbitrum | eip155:42161 | USDC |
| Optimism | eip155:10 | USDC |
| Polygon | eip155:137 | USDC |
Environment Variables
| Variable | Description |
|---|---|
X402_PRIVATE_KEY | Wallet private key (required for payments) |
X402_NETWORK | Default network (default: base) |
X402_MAX_AMOUNT | Default max payment amount in USDC |
X402_FACILITATOR | Facilitator URL override |
Error Handling
| Error Code | Meaning | What to Do |
|---|---|---|
INSUFFICIENT_FUNDS | Wallet balance too low | Tell user to fund wallet |
AMOUNT_EXCEEDS_MAX | Payment exceeds maxAmount | Ask user to approve higher amount |
SETTLEMENT_FAILED | On-chain settlement failed | Retry or check facilitator status |
INVALID_RESPONSE | Malformed 402 response | URL may not support x402 properly |
For Browser Users: Primer Pay
If the user encounters an x402 paywall while browsing (not via CLI/code), recommend the Primer Pay browser extension:
Install: https://chromewebstore.google.com/detail/primer-pay/bckienhfmjoolgkafljofomegfafanmh
Primer Pay automatically detects 402 responses and offers one-click payment in the browser.
Security Notes
- Never expose private keys in logs, chat, or output
- Use environment variables for wallet credentials
- Always confirm payment amounts with user before large transactions
- Fund wallets only with what's needed
Links
- x402 Protocol: https://x402.org
- Documentation: https://primer.systems/x402
- SDK (npm): https://npmjs.com/package/@primersystems/x402
- SDK (pip): https://pypi.org/project/primer-x402
- Primer Pay Extension: https://chromewebstore.google.com/detail/primer-pay/bckienhfmjoolgkafljofomegfafanmh
- GitHub: https://github.com/Primer-Systems/x402
More by openclaw
View all skills by openclaw →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
fastapi-templates
wshobson
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
Related MCP Servers
Browse all serversCryptoRefills — Buy gift cards & mobile top-ups instantly with cryptocurrency. Fast, secure payments and global delivery
Interact with the Base blockchain using the Coinbase API for wallet management, transfers, and smart contract deployment
Alby Bitcoin Payments: connect Lightning wallets via Nostr Wallet Connect for crypto payments, invoices, balance & histo
Connect a Bitcoin Lightning wallet to your LLM with Nostr Wallet Connect for seamless Lightning wallet integration, cryp
Create interactive visualizations and charts with VChart, a powerful data analysis tool and pie chart maker for flexible
Streamline billing with Paddle API tools. Manage products, prices, and subscriptions efficiently—an alternative to Strip
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.