x402 Middleware Configuration

Enable your platform or merchant to accept agent payments over x402, settled and facilitated by zerohash.

Overview & Concepts

This guide applies to whichever entity actually operates the server receiving agent payments - that may be your Platform directly (if you run the paid endpoint yourself), or a merchant onboarded under your Platform (if a business customer of yours runs the paid endpoint). The configuration steps are identical either way; only who performs them differs.

If the relevant server already accepts (or plans to accept) x402 payments, no new integration is required to use zerohash. x402 middleware is generic by design - the protocol does not mandate a single facilitator, and any standard x402 middleware package can point at any spec-compliant facilitator. Selecting zerohash is a configuration change: point the existing (or new) x402 middleware at zerohash's facilitator URL and credentials, in place of a generic or third-party facilitator.

This guide covers:

  • Install standard x402 middleware for your server framework
  • Configure zerohash as your facilitator
  • Define your paid route(s)
  • Verify the configuration
📘

Note

If a merchant is operating the server, your Platform is responsible for ensuring the merchant completes these steps - merchants do not have direct API access to zerohash (see Onboard your merchant), but they configure their own server-side middleware independently, using facilitator credentials provided to them via your Platform.

Authentication

Authentication for payment facilitation for x402 uses the same standard credential mechanisms.

Steps

1 - Choose your x402 middleware

Whoever operates the server, your Platform or your merchant, has two options for how to speak x402. Both of these options result in zerohash acting as your facilitator; they differ in how much configuration is handled for you versus configured manually.

Option A: Use zerohash's x402 middleware - zerohash provides a middleware package pre-wired to our facilitator, with built-in support for participant_code and account_label scoping, agent permissions, and transaction limits. This is the fastest path if you want facilitator selection and zerohash-specific configuration (KYA-linked participants, agent-level limits) handled together, rather than as separate steps.

Option B: Use a third-party or open-source x402 middleware package - x402 middleware is generic by design, the protocol does not mandate a single facilitator, and any standard, spec-compliant middleware (e.g., x402-express for Node.js, x402 for Python/FastAPI) can point at any spec-compliant facilitator, including zerohash's. Choose this option if you're already running x402 elsewhere and want to add zerohash as a facilitator without changing your existing middleware.

2 - Configure zerohash as your facilitator

Point the middleware's facilitator configuration at zerohash, using the credentials from the Authentication step. Contact your zerohash representative for more information.

3 - Define your paid route(s)

Apply the middleware to whichever endpoint(s) should be charged for, specifying price, accepted asset, and network. This is done by whoever operates the server (either the Platform or the Merchant).

Node.js / Express:

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

const app = express();

app.use(
  paymentMiddleware(
    "0xYourAddress",
    {
      "/forecast": {
        price: "$0.001",
        network: "base",
      },
    },
    facilitator
  )
);

Python / FastAPI:

from x402.server import x402ResourceServer

server = x402ResourceServer(facilitator)
server.register("eip155:8453", scheme)  # Base mainnet

4 - Verify the configuration

Send a request to the configured route without a payment attached. You should receive a 402 Payment Required response containing the configured price, asset, and network.

GET /forecast?city=chicago :

{
  "accepts": [
    {
      "scheme": "exact",
      "network": "base",
      "amount": "0.001",
      "asset": "USDC",
      "pay_to": "0xYourAddress"
    }
  ]
}

Once this response resolves correctly, the Platform or merchant is ready to accept agent payments settled through zerohash. See Move On-chain Money for the full payment flow, covering both the zerohash-controlled and external wallet models.


What’s Next

Did this page help you?