Skip to content

nuwa-protocol/okx-facilitator

Repository files navigation

okx-facilitator Monorepo

Workspace that packages the okx-facilitator library and ships runnable examples for building x402 facilitator flows on top of OKX's X Layer network.

Contents

  • 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.

Prerequisites

  • Node.js 18 or newer
  • pnpm (the repo is configured for pnpm@9.15.4, declared in package.json)

Install dependencies once at the workspace root:

pnpm install

Building the Library

The facilitator package is written in TypeScript and compiles to ESM output under dist/.

pnpm -C packages/okx-facilitator build

Run the package tests with:

pnpm -C packages/okx-facilitator test

Using okx-facilitator

After 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.

Running the Example

The Hono sample demonstrates end-to-end request gating backed by OKX's facilitator:

pnpm -C examples/okx-facilitator-hono dev

Populate the .env file with your OKX credentials before starting the server. Refer to examples/okx-facilitator-hono/README.md for detailed configuration guidance.

Release Workflow

  1. Update and test the library: pnpm -C packages/okx-facilitator test
  2. Build the package: pnpm -C packages/okx-facilitator build
  3. Publish from packages/okx-facilitator (after ensuring dist/ is up to date)

Lincese

MIT

A project by Nuwa AI with ❤️

About

The okx facilitator helper that handles the API access signature and also a customized paywall

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published