コンテンツにスキップ

CreateX402HandlerParams

このコンテンツはまだ日本語訳がありません。

Defined in: src/x402/server.ts:96

Parameters for createX402Handler.

Properties

facilitator

readonly facilitator: Facilitator

Defined in: src/x402/server.ts:98

Facilitator that performs verify and settle (self or HTTP-proxied).


handler

readonly handler: X402InnerHandler

Defined in: src/x402/server.ts:113

The protected business-logic handler. Invoked after settlement.


hooks?

readonly optional hooks?: ObservabilityHooks

Defined in: src/x402/server.ts:125

Optional observability callbacks. The handler emits onPaymentRequired each time it returns a 402, and onPaymentAccepted after a settled payment unlocks the inner handler. Hooks are fire-and-forget — see ObservabilityHooks.


idempotency?

readonly optional idempotency?: IdempotencyServerConfig

Defined in: src/x402/server.ts:135

Reasoning-step idempotency (M5-1, Half A). Default-on: when omitted, an in-memory store deduplicates re-sent / concurrent paid requests — replaying the cached response and closing the verify→settle TOCTOU. Pass { store: "none" } to disable, or a shared store (Redis/SQL adapter) for multi-replica deployments (the in-memory default is single-process). Fund-correctness never depends on this store — the on-chain EIP-3009 nonce is the backstop.


requirementsFor

readonly requirementsFor: (request) => readonly X402PaymentRequirements[] | Promise<readonly X402PaymentRequirements[] | null> | null

Defined in: src/x402/server.ts:106

Returns the X402PaymentRequirements that apply to this request.

  • Return one or more entries to require payment (client picks one).
  • Return null or [] to skip the payment flow entirely for this request — the inner handler is invoked with context = null.

Parameters

request

Request

Returns

readonly X402PaymentRequirements[] | Promise<readonly X402PaymentRequirements[] | null> | null


resourceFor?

readonly optional resourceFor?: (request) => X402ResourceInfo | Promise<X402ResourceInfo>

Defined in: src/x402/server.ts:118

Optional builder for the X402ResourceInfo echoed in the 402 response. Defaults to { url: request.url }.

Parameters

request

Request

Returns

X402ResourceInfo | Promise<X402ResourceInfo>


settlementPendingRetries?

readonly optional settlementPendingRetries?: number

Defined in: src/x402/server.ts:150

How many times to resend the identical /settle when the facilitator answers settlement_pending (x402 v2 §9: broadcast, confirmation not yet established — non-terminal). Default 1, as the x402 reference server does.

Still pending after the resends: the client gets 402 with a PAYMENT-RESPONSE header carrying errorReason: "settlement_pending" and the transaction hash, so it can reconcile on chain — the payment may still land, and paying again would pay twice. The idempotency lease is kept, so a duplicate of that request is not settled again: while the payment is still pending it is answered payment_in_progress. (Verify runs first, so once the transaction confirms, a duplicate is refused by verify — the nonce is spent.)