- Home
- Skills
- Web3 & Crypto
- X402 Integration
X402 Integration
Add x402 pay-per-call USDC payments to HTTP APIs without requiring user accounts or subscriptions.
$15
X402 Integration
Example session with this skill installed
Help me add x402 payments to my Express API. I want to charge 0.05 USDC on Base for the /v1/analyze endpoint. I need the server-side setup and the idempotency logic.
- Read your context and instructions
- Compiled the x402 integration
I have outlined the x402 integration for your Express API. This setup includes the 402 response structure, the Coinbase CDP facilitator configuration, and the required idempotency middleware to prevent double-charging.
x402 Express Integration Plan
const express = require('express');
const { x402 } = require('@x402/express');
const crypto = require('crypto');
const app = express();
// Simple in-memory store for idempotency (use Redis for production)
const settlementCache = new Map();
const x402Options = {
facilitator: 'https://api.cdp.coinbase.com/platform/v2/x402',
accepts: [
{
scheme: 'exact',
network: 'eip155:8453', // Base
asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
amount: '50000', // 0.05 USDC (6 decimals)
payTo: '0xYourWalletAddress...',
maxTimeoutSeconds: 3600
}
]
};
app.get('/v1/analyze', async (req, res) => {
const signature = req.headers['payment-signature'];
if (!signature) {
return res.status(402).json({
x402Version: '1.0.0',
accepts: x402Options.accepts
});
}
// Idempotency check
const paymentHash = crypto.createHash('sha256').update(signature).digest('hex');
if (settlementCache.has(paymentHash)) {
return res.json(settlementCache.get(paymentHash));
}
try {
// 1. Verify with facilitator
// 2. Run analysis logic
const result = { data: "Analysis complete", timestamp: Date.now() };
// 3. Settle and Cache
settlementCache.set(paymentHash, result);
res.setHeader('payment-response', 'success');
return res.json(result);
} catch (err) {
return res.status(500).json({ error: "Processing failed" });
}
});
Next steps
- Replace
0xYourWalletAddress...with your actual Base settlement address. - Install the middleware via
npm install @x402/express @x402/evm. - Test the flow using a testnet facilitator before switching to Base mainnet.
Connects securely to your tools. The creator never sees your data.
About this skill
API monetization is often blocked by the friction of accounts, credit cards, and subscription tiers. This skill implements the x402 protocol to enable pay-per-call HTTP payments using USDC on EVM networks.
What it does
- Protocol implementation enables the HTTP 402 Payment Required flow for any REST endpoint.
- EIP-712 signing configures secure authorization payloads for client-side payment execution.
- Multi-network support structures payment acceptance across Base, Polygon, Arbitrum, and World Chain.
- Idempotency logic prevents double-charging by implementing payment hash caching and response replays.
- Facilitator integration connects endpoints to Coinbase CDP or self-hosted settlement facilitators.
How it works
- Define assets by selecting the network, USDC atomic units, and price granularity for your endpoints.
- Configure middleware using
@x402/express,@x402/hono, or@x402/nextto handle the 402 response body. - Implement storage for settlement hashes to ensure exactly-once execution.
- Deploy client wrappers using
@x402/fetchto allow agents and automated callers to pay automatically.
Frameworks & tools
The skill supports Express, Hono, Next.js, and Cloudflare Workers. It utilizes the @x402/evm and @x402/fetch libraries for EIP-712 signing and request wrapping.
Why this beats prompting it yourself
Handling the 402 response body manually often leads to malformed accepts entries that clients cannot parse. This skill enforces the exact EIP-712 payload structure and idempotency guards required to prevent payment failures or double-billing.
Use cases
- Monetize AI agents by charging small amounts of USDC per inference or data request.
- Protect expensive APIs from scraping by requiring a micro-payment for high-value data.
- Accountless billing for services where you want to avoid managing user databases or passwords.
- Cross-chain payments allowing clients on different L2s to access a single service.
Known limitations
Requires an external facilitator like Coinbase CDP for settlement. Only supports EVM-compatible networks and assets.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 5 days ago
Requires
Nothing to install.
Permissions
No special permissions declared or detected
What's inside
Frequently Asked Questions
New in Web3 & Crypto
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Web3 & Crypto.