createX402Handler
このコンテンツはまだ日本語訳がありません。
createX402Handler(
params):X402RequestHandler
Defined in: src/x402/server.ts:212
Builds an X402RequestHandler that wraps params.handler with the
x402 payment flow.
Parameters
params
Returns
Example
import { createServer } from "node:http";import { parseUnits } from "viem";import { buildPaymentRequirements, createSelfFacilitator, createX402Handler, JPYC_DECIMALS, JPYC_V2_ADDRESS, polygonAmoy,} from "kawasekit";
const handler = createX402Handler({ facilitator: createSelfFacilitator({ walletClient, publicClient }), requirementsFor: (req) => new URL(req.url).pathname.startsWith("/weather") ? [buildPaymentRequirements({ chainId: polygonAmoy.id, asset: JPYC_V2_ADDRESS, payTo: "0x...", amount: parseUnits("0.001", JPYC_DECIMALS), })] : null, handler: async (req) => new Response(JSON.stringify({ weather: "sunny" }), { headers: { "content-type": "application/json" }, }),});
// Mount on any framework that exposes WHATWG Request → Response.