Skip to main content
The Hono middleware works the same way as Express but uses Hono’s middleware API.
pnpm add @faremeter/middleware @faremeter/info hono

Basic setup

import { Hono } from "hono"
import { createMiddleware } from "@faremeter/middleware/hono"
import { xSolanaSettlement } from "@faremeter/info/solana"

const app = new Hono()

const paymentWall = await createMiddleware({
  facilitatorURL: "https://facilitator.corbits.dev",
  accepts: [
    xSolanaSettlement({
      network: "devnet",
      payTo: "7xKXwxRPMo2sUAT5...",
      asset: "USDC",
      amount: "10000",
    }),
  ],
})

app.get("/protected", paymentWall, (c) => {
  return c.json({ data: "paid content" })
})

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

export { app }

App-level middleware

app.use("/*", paymentWall)

Multiple payment methods

Same configuration as Express — pass multiple requirements to the accepts array:
import { xSolanaSettlement } from "@faremeter/info/solana"
import { x402Exact } from "@faremeter/info/evm"

const paymentWall = await createMiddleware({
  facilitatorURL: "https://facilitator.corbits.dev",
  accepts: [
    xSolanaSettlement({ network: "devnet", payTo: "7xKX...", asset: "USDC", amount: "10000" }),
    x402Exact({ network: "base-sepolia", payTo: "0x1234...", asset: "USDC", amount: "10000" }),
  ],
})

Differences from Express

The core logic is identical. The only difference is the middleware signature:
  • Express: (req, res, next) => void
  • Hono: (c, next) => Promise<void>
The createMiddleware function from @faremeter/middleware/hono returns a Hono-compatible middleware. Configuration, payment requirements, and facilitator interaction are the same.

Further reading