Workspace that packages the okx-facilitator library and ships runnable examples for building x402 facilitator flows on top of OKX's X Layer network.
packages/okx-facilitator– reusable utilities for signing x402 requests, composing facilitator headers, and rendering an OKX-branded checkout paywall. See the package README for API-level documentation.examples/okx-facilitator-hono– minimal Hono server that protects a route with x402 payments using the facilitator package.
- Node.js 18 or newer
- pnpm (the repo is configured for
pnpm@9.15.4, declared inpackage.json)
Install dependencies once at the workspace root:
pnpm installThe facilitator package is written in TypeScript and compiles to ESM output under dist/.
pnpm -C packages/okx-facilitator buildRun the package tests with:
pnpm -C packages/okx-facilitator testAfter installing from npm (or linking locally during development) the facilitator exposes helpers for generating a turnkey checkout page:
import { getOkxPaywallHtml } from "okx-facilitator";
const html = getOkxPaywallHtml({
amount: 1.25,
currentUrl: "https://example.com/protected",
paymentRequirements,
network: "x-layer",
assetAddress: "0x0000000000000000000000000000000000000000",
assetName: "USDC",
cdpClientKey,
appName: "My App",
appLogo: "https://example.com/logo.png",
sessionTokenEndpoint: "https://example.com/api/session",
});Serve the returned HTML when a client needs to complete an x402 transaction. The bundled script handles wallet connections, X Layer network enforcement, and emits an X-PAYMENT header once the authorization succeeds.
The Hono sample demonstrates end-to-end request gating backed by OKX's facilitator:
pnpm -C examples/okx-facilitator-hono devPopulate the .env file with your OKX credentials before starting the server. Refer to examples/okx-facilitator-hono/README.md for detailed configuration guidance.
- Update and test the library:
pnpm -C packages/okx-facilitator test - Build the package:
pnpm -C packages/okx-facilitator build - Publish from
packages/okx-facilitator(after ensuringdist/is up to date)
MIT
A project by Nuwa AI with ❤️