X402 Integration

    by Khristian Kopachelli

    1

    Add x402 pay-per-call USDC payments to HTTP APIs without requiring user accounts or subscriptions.

    $15

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    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

    1. Replace 0xYourWalletAddress... with your actual Base settlement address.
    2. Install the middleware via npm install @x402/express @x402/evm.
    3. 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

    1. Define assets by selecting the network, USDC atomic units, and price granularity for your endpoints.
    2. Configure middleware using @x402/express, @x402/hono, or @x402/next to handle the 402 response body.
    3. Implement storage for settlement hashes to ensure exactly-once execution.
    4. Deploy client wrappers using @x402/fetch to 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    Listed5 days ago

    What's inside

    Frequently Asked Questions

    The X402 Integration implements a standardized HTTP 402 "Payment Required" flow, allowing you to charge micro-payments in USDC per API call. This eliminates the need for user accounts, credit cards, or complex subscription tiers, making it ideal for autonomous agents.

    This skill is designed for programmatic callers and supports any AI agent or application using `@x402/fetch` or compatible request wrappers. It integrates seamlessly with popular web frameworks like Express, Hono, Next.js, and Cloudflare Workers.

    You will receive the pre-configured middleware logic, EIP-712 signing configurations for secure authorization, and the idempotency handling patterns required to prevent double-charging. It also includes the setup structures for connecting to settlement facilitators like Coinbase CDP.

    The integration handles payment acceptance across major EVM-compatible Layer 2 networks, including Base, Polygon, Arbitrum, and World Chain. This allows you to accept USDC from clients regardless of which of these supported networks they are using.

    The skill includes specialized idempotency logic that caches payment hashes and handles response replays. This ensures that if a network glitch occurs after a payment is sent, the client isn't charged a second time for the same request.

    You will need an external settlement facilitator, such as Coinbase CDP or a self-hosted alternative, to process the actual on-chain transactions. The skill manages the protocol and communication between your API and the facilitator but does not act as the wallet or liquidator itself.

    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.