TypeScript SDK
x402.facilitator
Creates a facilitator for the x402 payment protocol.
You can use this with settlePayment
or with any x402 middleware to enable settling transactions with your thirdweb server wallet.
import { facilitator } from "thirdweb/x402";import { createThirdwebClient } from "thirdweb";import { paymentMiddleware } from "x402-hono"; const client = createThirdwebClient({ secretKey: "your-secret-key",});const thirdwebX402Facilitator = facilitator({ client: client, serverWalletAddress: "0x1234567890123456789012345678901234567890",}); // add the facilitator to any x402 payment middlewareconst middleware = paymentMiddleware( "0x1234567890123456789012345678901234567890", { "/api/paywall": { price: "$0.01", network: "base-sepolia", config: { description: "Access to paid content", }, }, }, thirdwebX402Facilitator,);
const thirdwebX402Facilitator = facilitator({ client: client, serverWalletAddress: "0x1234567890123456789012345678901234567890", // Optional: Wait behavior for settlements // - "simulated": Only simulate the transaction (fastest) // - "submitted": Wait until transaction is submitted // - "confirmed": Wait for full on-chain confirmation (slowest, default) waitUntil: "confirmed",});
The configuration for the facilitator
let config: { baseUrl?: string; serverWalletAddress: string; vaultAccessToken?: string;};
let returnType: { address: string; createAuthHeaders: () => Promise<{ list: Record<string, string>; settle: Record<string, string>; supported: Record<string, string>; verify: Record<string, string>; }>; settle: ( payload: RequestedPaymentPayload, paymentRequirements: RequestedPaymentRequirements, ) => Promise<FacilitatorSettleResponse>; supported: (filters?: { chainId: number; tokenAddress?: string; }) => Promise<FacilitatorSupportedResponse>; url: `${string}://${string}`; verify: ( payload: RequestedPaymentPayload, paymentRequirements: RequestedPaymentRequirements, ) => Promise<FacilitatorVerifyResponse>;};
a x402 compatible FacilitatorConfig