x402-router.wgw.lol

Route everyx402 payment.

One facilitator URL - . The router sends each payment to PrimeV, CDP, PayAI, Dexter, Sluzen or x402.org by network. Set this URL as the url in HTTPFacilitatorClient. The middleware calls /supported, /verify and /settle there, like any other facilitator.

const facilitator = new HTTPFacilitatorClient({ url: "https://x402-router.wgw.lol" });
Full example

Ethereum Mainnet goes to PrimeV.

Just 1.2s settlement on Mainnet.. with sponsored gas. No authentication needed.

EVM and Solana go to PayAI, Dexter or CDP.

Testnets included. With no keys, PayAI goes first on its free credits, then Dexter.

XRP Ledger goes to Sluzen.

Mainnet and testnet, for sellers with a Sluzen account. Register your resource URL with Sluzen first. On testnet, Sluzen goes first, then x402.org.

Other testnets go to x402.org.

Base Sepolia, Solana Devnet and more. No auth header needed.

A CDP or PayAI key goes first.

The createRouterAuthHeaders helper signs short-lived JWTs on your server and sends them as X-Forwarded-CDP-Token and X-Forwarded-PayAI-Token. The router copies each one to authorization only for its own facilitator. With both keys, CDP goes first.

You choose the order per chain.

Name the facilitators you prefer for each chain or network. The same order decides which one settles the payment.

When one fails, the next one tries.

The router moves on when a facilitator is out of credits, down, or does not support the payment. It stops when the payment itself is invalid, such as a bad signature. A Solana payment goes only to the facilitator whose fee payer the buyer signed.

The buyer gets a reason to act on.

For example, a missing one-time Permit2 approval, or a seller whose provider is out of credits. The extra.router.tried field lists every facilitator the router asked and what each one said.

No accounts. No database. Nothing stored.

The router reads x402Version, scheme and network, picks the upstream, and passes back its answer.

The full seller setup.

The @tunnckocore scoped packages should be installed from npm.wgw.lol, not npmjs.com! Add the scope line to your .npmrc first, then install as usual. Everything after the facilitator is the standard x402 setup.

.npmrc

Terminal

import {
  BASE_MAINNET,
  createRouterAuthHeaders,
  ETHEREUM_MAINNET,
  SOLANA_MAINNET,
} from "@tunnckocore/x402-router";
import { HTTPFacilitatorClient, x402ResourceServer } from "@x402/core/server";
import { ExactEvmScheme } from "@x402/evm/exact/server";
import { paymentMiddleware } from "@x402/hono";
import { ExactSvmScheme } from "@x402/svm/exact/server";
import { Hono } from "hono";

const app = new Hono();

// Every part is optional. With none, PayAI goes first, then Dexter.
const facilitator = new HTTPFacilitatorClient({
  url: "https://x402-router.wgw.lol",
  createAuthHeaders: () =>
    createRouterAuthHeaders({
      cdp: {
        apiKeyId: process.env.CDP_API_KEY_ID,
        apiKeySecret: process.env.CDP_API_KEY_SECRET,
      },
      payai: {
        apiKeyId: process.env.PAYAI_API_KEY_ID,
        apiKeySecret: process.env.PAYAI_API_KEY_SECRET,
      },
      preference: {
        eip155: ["cdp", "payai", "dexter"],
        solana: ["payai", "dexter", "cdp"],
      },
    }),
});

const server = new x402ResourceServer(facilitator)
  .register(ETHEREUM_MAINNET, new ExactEvmScheme())
  .register(BASE_MAINNET, new ExactEvmScheme())
  .register(SOLANA_MAINNET, new ExactSvmScheme());

app.use(
  paymentMiddleware(
    {
      "GET /paid": {
        accepts: [{ 
          scheme: "exact", 
          network: ETHEREUM_MAINNET,
          payTo: "0xYourAddress",
          price: "$1"
        }],
        description: "Paid example endpoint",
      },
    },
    server,
  ),
);

app.get("/paid", (c) => c.json({ ok: true, message: "paid endpoint reached" }));

Or run your own.

The same package runs the hosted router. Deploy it to Cloudflare Workers, Deno, Bun, Node, or any runtime with the Fetch API.

import { createX402Router } from "@tunnckocore/x402-router";

// Pass { upstreams } to add or replace facilitators.
const router = createX402Router();

// export default { fetch: router.fetch };

// Deno.serve({ fetch: router.fetch });

// or using @hono/node-server, or Node.js built-in
// serve({ fetch: router.fetch })
upstreamsPrimeV, CDP, PayAI, Dexter, Sluzen, x402.orgPass a list of your own facilitators, each { name, facilitatorUrl, auth?, supportedKinds? }
supportedliveA fixed /supported response. When set, the router skips live discovery and routes by each upstream's list.
forwardedBearerHeaderX-Forwarded-CDP-TokenThe request header that carries the seller's token for forwarded-bearer upstreams.
cacheControlpublic, max-age=300The cache-control header on /supported.
fetchglobalThis.fetchThe function used for calls to upstream facilitators.