x402kapy
v0.1.4
Published
SDK for x402kapy — KAPY & USDC payment configs for the x402 protocol on Base
Maintainers
Readme
x402kapy SDK
KAPY & USDC payment configs for the x402 protocol on Base.
Install
npm install x402kapy @x402/next @x402/core @x402/evmQuick Start
Protect a Next.js API route
// app/api/premium/route.ts
import { withX402 } from "@x402/next";
import { x402ResourceServer, FacilitatorClient } from "@x402/core";
import { ExactEvmScheme } from "@x402/evm";
import { kapyAccepts, BASE_MAINNET } from "x402kapy";
const facilitator = new FacilitatorClient({ url: "https://facilitator.x402.org" });
const server = new x402ResourceServer(facilitator)
.register(BASE_MAINNET, new ExactEvmScheme());
const handler = async (request: NextRequest) => {
return NextResponse.json({ data: "premium content" });
};
export const GET = withX402(handler, kapyRoute({
price: "1", // 1 KAPY or 1 USDC
tokens: "both",
}), server);Discover available services
import { discover } from "x402kapy";
const { items } = await discover();
for (const service of items) {
console.log(service.metadata.name, service.resource);
}API
Constants
| Export | Value |
|--------|-------|
| KAPY | { address, decimals: 18, symbol: "KAPY", ... } |
| USDC | { address, decimals: 6, symbol: "USDC", ... } |
| BASE_MAINNET | "eip155:8453" |
| BASE_SEPOLIA | "eip155:84532" |
| DEFAULT_PAY_TO | "0xc406fFf2Ce8b5dce517d03cd3531960eb2F6110d" |
| CATEGORIES | ["api", "ai", "data", "storage", "compute", "mcp", "infrastructure", "other"] |
kapyRoute(opts)
Builds x402 RouteConfig for KAPY and/or USDC payments. Pass to withX402().
| Option | Default | Description |
|--------|---------|-------------|
| price | required | Human-readable price (e.g. "1", "0.5") |
| payTo | DEFAULT_PAY_TO | Address receiving payment |
| tokens | "both" | "kapy", "usdc", or "both" |
| network | BASE_MAINNET | Network identifier |
| description | "" | What the buyer gets |
| mimeType | "application/json" | Response MIME type |
| timeoutSeconds | 60 | Payment timeout |
toAtomic(price, token) / fromAtomic(atomic, token)
Convert between human-readable and on-chain atomic units.
toAtomic("1", KAPY) // "1000000000000000000"
toAtomic("0.5", USDC) // "500000"
fromAtomic("1000000000000000000", KAPY) // "1"discover(baseUrl?)
Fetch the x402kapy Bazaar-compatible discovery endpoint. baseUrl defaults to https://x402kapy.moikapy.workers.dev.
kapySchemes()
Returns scheme registrations for Base mainnet. Requires @x402/evm peer dependency.
License
MIT
