@@ -9,10 +9,12 @@ import type {
99 RequestedPaymentRequirements ,
1010} from "./schemas.js" ;
1111
12+ export type WaitUntil = "simulated" | "submitted" | "confirmed" ;
13+
1214export type ThirdwebX402FacilitatorConfig = {
1315 client : ThirdwebClient ;
1416 serverWalletAddress : string ;
15- waitUtil ?: "simulated" | "submitted" | "confirmed" ;
17+ waitUtil ?: WaitUntil ;
1618 vaultAccessToken ?: string ;
1719 baseUrl ?: string ;
1820} ;
@@ -37,6 +39,7 @@ export type ThirdwebX402Facilitator = {
3739 settle : (
3840 payload : RequestedPaymentPayload ,
3941 paymentRequirements : RequestedPaymentRequirements ,
42+ waitUtil ?: WaitUntil ,
4043 ) => Promise < FacilitatorSettleResponse > ;
4144 supported : ( filters ?: {
4245 chainId : number ;
@@ -81,6 +84,21 @@ const DEFAULT_BASE_URL = "https://api.thirdweb.com/v1/payments/x402";
8184 * },
8285 * thirdwebX402Facilitator,
8386 * );
87+ * ```
88+ *
89+ * #### Configuration Options
90+ *
91+ * ```ts
92+ * const thirdwebX402Facilitator = facilitator({
93+ * client: client,
94+ * serverWalletAddress: "0x1234567890123456789012345678901234567890",
95+ * // Optional: Wait behavior for settlements
96+ * // - "simulated": Only simulate the transaction (fastest)
97+ * // - "submitted": Wait until transaction is submitted
98+ * // - "confirmed": Wait for full on-chain confirmation (slowest, default)
99+ * waitUntil: "confirmed",
100+ * });
101+
84102 * ```
85103 *
86104 * @bridge x402
@@ -167,12 +185,14 @@ export function facilitator(
167185 async settle (
168186 payload : RequestedPaymentPayload ,
169187 paymentRequirements : RequestedPaymentRequirements ,
188+ waitUtil ?: WaitUntil ,
170189 ) : Promise < FacilitatorSettleResponse > {
171190 const url = config . baseUrl ?? DEFAULT_BASE_URL ;
172191
173192 let headers = { "Content-Type" : "application/json" } ;
174193 const authHeaders = await facilitator . createAuthHeaders ( ) ;
175194 headers = { ...headers , ...authHeaders . settle } ;
195+ const waitUtilParam = waitUtil || config . waitUtil ;
176196
177197 const res = await fetch ( `${ url } /settle` , {
178198 method : "POST" ,
@@ -181,7 +201,7 @@ export function facilitator(
181201 x402Version : payload . x402Version ,
182202 paymentPayload : payload ,
183203 paymentRequirements : paymentRequirements ,
184- ...( config . waitUtil ? { waitUtil : config . waitUtil } : { } ) ,
204+ ...( waitUtilParam ? { waitUtil : waitUtilParam } : { } ) ,
185205 } ) ,
186206 } ) ;
187207
0 commit comments