Keryx®
SDK · v0.1

Ship a paid tool in five minutes.

@keryxhq/middleware wraps any HTTP handler so agents can pay per call with x402 + USDC on Arc. Zero runtime deps. You are payTo onchain (100% of the call today). The 5% platform fee is ledger accounting until split settlement ships.

$pnpm add @keryxhq/middleware viem
npm@keryxhq/middlewareAlso works with npm and yarn. viem is a peer dep.
Next.js

The whole integration.

typescript
// app/api/my-tool/route.ts
import { paidHandler } from "@keryxhq/middleware/next";

export const POST = paidHandler({
  price: 0.004,                           // USD per call
  wallet: "0xYourArcWallet...",           // where payment lands
  description: "Web search over indexed docs.",
  handler: async ({ query }: { query: string }) => {
    return { results: await mySearch(query) };
  },
});

First hit returns 402. Agent pays. Your handler runs. That’s the whole thing.

What happens under the hood

Three steps. The SDK does all three.

01

Agent calls your endpoint

POST /api/my-tool with no X-PAYMENT header. The SDK returns HTTP 402 + a machine-readable body: exact USDC amount, asset address, your wallet, network, expiry.

02

Agent signs and retries

The agent reads the 402, signs an EIP-3009 USDC authorization to your wallet for the exact amount, base64-encodes it, retries the same request with X-PAYMENT set.

03

SDK verifies, your handler runs

Three-tier verification: structural (amount, recipient, expiry), cryptographic (EIP-3009 signer recovery via viem), and optional settlement (facilitator broadcasts onchain and returns a tx hash). Your handler runs with the receipt attached — you never touch the payment logic.

Express

Same idea, connect-style.

typescript
import express from "express";
import { paidExpress } from "@keryxhq/middleware/express";

const app = express();
app.use(express.json());

app.post(
  "/api/my-tool",
  paidExpress({
    price: 0.004,
    wallet: "0xYourArcWallet...",
    description: "Web search over indexed docs.",
  }),
  (req, res) => {
    // req.keryxPayment holds the verified receipt
    res.json({ results: mySearch(req.body.query) });
  },
);
Not on Next.js or Express?

Use the framework-agnostic primitives.

typescript
import {
  buildRequirements,
  decodePaymentHeader,
  verifyPayment,
  buildX402Body,
} from "@keryxhq/middleware";

// Use these if you're not on Next.js or Express — Cloudflare Workers,
// Deno, Fastify, Hono, bare Node http.Server, etc.

Cloudflare Workers, Deno, Hono, Fastify, bare Node http.Server. If you can read a header, you can accept x402.

Networks

Arc-native, USDC-priced.

The SDK ships with two Arc networks baked in. Arc is a stablecoin-native chain built by Circle where gas itself is denominated in USDC, so a sub-cent call doesn’t get eaten alive by transaction fees. That’s the only price band where per-call payments make sense.

NetworkChain idUSDC address
arc-testnet (default)50420020x3600…0000
arc-mainnet50420010x3600…0000
Ready to list your tool?

Deploy the wrapped handler. Publish the URL. Get paid.

One page. Wallet-signed. Your tool is discoverable to every agent in Claude, Cursor, and GitHub Copilot via MCP.