OpenX402

Quick Start

Start accepting x402 payments with the OpenX402 facilitator

Server Setup

Install the x402 middleware for your framework and point it at the OpenX402 facilitator. No sign up required.

With Express

npm install express x402-express
import express from "express";
import { paymentMiddleware } from "x402-express";

const app = express();

app.use(
  paymentMiddleware(
    "0xYourWalletAddress" as `0x${string}`,
    {
      "/api/premium": {
        price: "$0.10",
        network: "base",
        config: { description: "Premium API access" },
      },
    },
    {
      url: "https://facilitator.openx402.ai",
    }
  )
);

app.get("/api/premium", (req, res) => {
  res.json({ data: "premium content", payer: req.payer });
});

app.listen(3000);

With Hono

npm install hono x402-hono
import { Hono } from "hono";
import { paymentMiddleware } from "x402-hono";

const app = new Hono();

app.use(
  "/api/*",
  paymentMiddleware(
    "0xYourWalletAddress" as `0x${string}`,
    {
      "/api/premium": {
        price: "$0.10",
        network: "base",
        config: { description: "Premium API access" },
      },
    },
    {
      url: "https://facilitator.openx402.ai",
    }
  )
);

app.get("/api/premium", (c) => {
  return c.json({ data: "premium content" });
});

export default app;

Client Setup

Use x402-fetch to make payments automatically from the client side:

import { wrapFetch } from "x402-fetch";

const x402Fetch = wrapFetch(fetch, {
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
});

const response = await x402Fetch("https://your-server.com/api/premium");
const data = await response.json();

When the server returns 402 Payment Required, x402-fetch automatically:

  1. Reads the payment requirements from the response
  2. Signs a transferWithAuthorization with the client's private key
  3. Resends the request with the signed payment headers

The client never sends a transaction — it only signs an authorization that the facilitator executes on-chain.

Solana Client

import { wrapFetch } from "x402-fetch";
import { svm } from "x402/shared";

const signer = await svm.createSignerFromBase58(process.env.SOLANA_PRIVATE_KEY);
const x402Fetch = wrapFetch(fetch, signer);

const response = await x402Fetch("https://your-server.com/api/premium");
const data = await response.json();

Test on Base Sepolia

Use network: "base-sepolia" during development. Get testnet USDC from the Circle faucet.

Next Steps