Facilitator

⚙️ Latch Facilitator

The Latch Facilitator is the core payment-settlement engine that powers all x402 transactions within the Latch ecosystem. It manages blockchain interaction, payment verification, and settlement — ensuring each request is cryptographically validated before execution.

Developers can self-host a Facilitator or use the default instance operated by Latch.


🔄 How It Works

Client → Latch Facilitator → Your API

Flow:

  1. The client sends an API or MCP request.

  2. The server responds with a 402 Payment Required, including pricing metadata.

  3. The client (or proxy) sends the payment transaction.

  4. The Facilitator verifies and settles the payment on-chain.

  5. Once verified, the request proceeds and returns the final response.


🧩 Available Endpoint

Mainnet Facilitator: https://x402.latchmcp.app

This endpoint acts as a high-availability settlement layer across EVM and SVM networks. You can also host your own facilitator instance for full control over wallets, tokens, and chain routing.


🔐 Authentication

All Facilitator requests require authentication via your server wallet secret:

headers: {
  "Authorization": "Bearer <YOUR_WALLET_SECRET>"
}

You can generate or rotate your wallet secret from the Latch Console under “Account Settings”.


📡 Endpoints

Endpoint
Description

/verify

Verify a payment without settling it

/settle

Verify and settle a payment

/list

List all payable endpoints and pricing metadata

/supported

Get supported chains and tokens


🧠 Integration Methods

There are two main ways to integrate the Latch Facilitator into your service:

Method 1 — Using settlePayment() (recommended)

A simple helper for verifying and settling payments anywhere within your routes or middleware.

import { settlePayment, createFacilitator } from "@latchmcp/sdk";
import { base } from "@latchmcp/chains";

const facilitator = createFacilitator({
  walletSecret: process.env.LATCH_WALLET_SECRET,
});

export async function GET(request: Request) {
  const paymentData = request.headers.get("x-payment");

  const result = await settlePayment({
    resourceUrl: "https://api.example.com/premium",
    method: "GET",
    paymentData,
    network: "base",
    price: "$0.10",
    facilitator,
  });

  if (result.status === 200) {
    return Response.json({ message: "Premium content unlocked" });
  } else {
    return Response.json(result.responseBody, {
      status: result.status,
      headers: result.responseHeaders,
    });
  }
}

Parameters:

  • resourceUrl – Full URL of the paid endpoint.

  • method – HTTP method (GET, POST, etc.).

  • paymentData – x402 payment payload from the request header.

  • network – Target blockchain (e.g., base, solana, polygon).

  • price – Price in fiat or token units.

  • facilitator – Configured Facilitator instance.

Returns: An object with status, responseBody, and responseHeaders.


Method 2 — Using x402 Middleware Libraries

The Facilitator works seamlessly with x402-compatible middlewares, letting you add on-chain payments to your API with minimal setup.

Supported libraries:

  • x402-hono

  • x402-express

  • x402-next

Example (Hono):

import { Hono } from "hono";
import { paymentMiddleware } from "x402-hono";
import { createFacilitator } from "@latchmcp/sdk";

const facilitator = createFacilitator({
  walletSecret: process.env.LATCH_WALLET_SECRET,
});

const app = new Hono();

app.use(
  paymentMiddleware(
    process.env.LATCH_WALLET_ADDRESS,
    {
      "/api/paywall": {
        price: "$0.01",
        network: "base",
        config: { description: "Access to paid content" },
      },
      "/api/premium": {
        price: "$0.05",
        network: "base",
        config: { description: "Premium feature access" },
      },
    },
    facilitator
  )
);

app.get("/api/paywall", (c) => c.json({ message: "This is premium content!" }));
app.get("/api/premium", (c) => c.json({ message: "Premium features unlocked!" }));

export default app;

🧭 When to Use the Facilitator

Use the Latch Facilitator when you need:

  • Direct integration of payments into your backend logic.

  • Fine-grained control over transaction flow and validation.

  • To build custom middleware or enforce advanced business rules.

Use the Latch Payment Proxy when you prefer:

  • No-code or hosted setup.

  • Automatic forwarding and caching.

  • Rapid integration without modifying backend code.


📈 Next Steps

Last updated