x402 middleware
Read and write trust inside the HTTP 402 payment handshake, with zero extra round-trips.
x402 lets a server respond with 402 Payment Required and a set of payment terms; the client retries with a signed payment. Tessera hooks into that exact moment to enforce trust and record outcomes.
Express example
typescript
import express from "express";
import { x402 } from "x402-express";
import { tesseraGuard } from "@tessera/x402";
const app = express();
app.use(
"/api",
// require payment AND a minimum trust score
x402({ price: "$0.01", network: "solana" }),
tesseraGuard({ minScore: 800, minStake: 100 }),
);
app.get("/api/forecast", (req, res) => {
res.json({ data: "..." });
});tesseraGuardreads the caller’s score from cache in sub-millisecond time and auto-emits an attestation when the response succeeds.Client side
typescript
import { withX402 } from "x402-fetch";
import { attachIdentity } from "@tessera/x402";
const fetchPaid = attachIdentity(withX402(fetch), agentSigner);
// identity + payment are negotiated automatically
const res = await fetchPaid("https://api.example.com/api/forecast");What gets recorded
- The settled amount and counterparties.
- A hash of the x402 receipt, anchored via state compression.
- The outcome, which both sides can later dispute with evidence.
Standards alignment
The guard also speaks Google AP2 authorization objects and maps agent identities onto ERC-8004, so trust travels across ecosystems rather than locking you in.