> ## Documentation Index
> Fetch the complete documentation index at: https://docs.faremeter.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Express

> Setting up x402 payment middleware with Express.

The Express middleware adds x402 payment walls to individual routes or your entire application.

```bash theme={null}
pnpm add @faremeter/middleware @faremeter/info express
```

## Route-level middleware

Apply the middleware to specific routes:

```typescript theme={null}
import express from "express"
import { createMiddleware } from "@faremeter/middleware/express"
import { x402Exact } from "@faremeter/info/solana"

const app = express()

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

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

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

app.listen(3000)
```

## App-level middleware

Apply to all routes:

```typescript theme={null}
app.use(paymentWall)

app.get("/resource-a", (req, res) => {
  res.json({ data: "a" })
})

app.get("/resource-b", (req, res) => {
  res.json({ data: "b" })
})
```

## Multiple payment methods

Accept payments on different chains from the same endpoint:

```typescript theme={null}
// Aliased to avoid name collision — both chains export x402Exact
import { x402Exact as solanaX402Exact } from "@faremeter/info/solana"
import { x402Exact } from "@faremeter/info/evm"

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

## Different prices per route

Create separate middleware instances for different routes:

```typescript theme={null}
const cheapRoute = await createMiddleware({
  facilitatorURL: "https://facilitator.corbits.dev",
  accepts: [
    x402Exact({ network: "devnet", payTo: "7xKX...", asset: "USDC", amount: "1000" }),
  ],
})

const expensiveRoute = await createMiddleware({
  facilitatorURL: "https://facilitator.corbits.dev",
  accepts: [
    x402Exact({ network: "devnet", payTo: "7xKX...", asset: "USDC", amount: "100000" }),
  ],
})

app.get("/basic", cheapRoute, (req, res) => res.json({ tier: "basic" }))
app.get("/premium", expensiveRoute, (req, res) => res.json({ tier: "premium" }))
```

## Error handling

The middleware returns appropriate HTTP responses for payment errors:

* `402` -- No payment provided, returns requirements.
* `400` -- Malformed payment payload.
* `402` -- Payment verification or settlement failed, returns requirements again.

Errors from the facilitator are logged and translated into HTTP responses. Your route handler is only called after successful payment.

## Further reading

* [Hono](/server/hono) -- Alternative framework setup.
* [Middleware Overview](/server/middleware-overview) -- Configuration details.
