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.

Example

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 middleware
const middleware = paymentMiddleware(
"0x1234567890123456789012345678901234567890",
{
"/api/paywall": {
price: "$0.01",
network: "base-sepolia",
config: {
description: "Access to paid content",
},
},
},
thirdwebX402Facilitator,
);

Configuration Options

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",
});
function facilitator(

Parameters

The configuration for the facilitator

Type

let config: {
baseUrl?: string;
client: ThirdwebClient;
serverWalletAddress: string;
vaultAccessToken?: string;
waitUntil?: WaitUntil;
};

Returns

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,
waitUntil?: WaitUntil,
) => Promise<FacilitatorSettleResponse>;
supported: (filters?: {
chainId: number;
tokenAddress?: string;
}) => Promise<FacilitatorSupportedResponse>;
url: `${string}://${string}`;
verify: (
payload: RequestedPaymentPayload,
paymentRequirements: RequestedPaymentRequirements,
) => Promise<FacilitatorVerifyResponse>;
};

a x402 compatible FacilitatorConfig