@searchx402/sdk

Build x402 payment-enabled APIs on Cloudflare Workers in minutes

Import directly (no npm needed)

// In your Cloudflare Worker
import { createX402Tool } from 'https://searchx402.com/sdk/index.mjs';

Quick Start

// wrangler.toml: name = "my-x402-tool"

import { createX402Tool } from 'https://searchx402.com/sdk/index.mjs';

export default createX402Tool({
  name: 'My AI Tool',
  price: 0.05,  // $0.05 USDC per request
  wallet: '0x...your-wallet-address',
  handler: async (request, env) => {
    const { prompt } = await request.json();
    // Your tool logic here
    return { result: 'Generated content...' };
  }
});

SDK Files

Download or import directly from these URLs:

What You Get

HTTP 402 Handling

Automatic payment requirement responses following x402 protocol

Payment Verification

Built-in receipt parsing and validation helpers

CORS Enabled

Cross-origin requests work out of the box

Type Safety

Full TypeScript definitions included

Exports

createX402Tool    // Factory function to create x402 apps
X402Response      // HTTP 402 response class
verifyPayment     // Payment receipt verification
parsePaymentReceipt
encodePaymentReceipt
toUsdcUnits / fromUsdcUnits
jsonResponse / errorResponse
generateRequestId