Facilitator client
FacilitatorClient from @chainsafe/x402-client calls a facilitator's /v2/verify, /v2/settle and /v2/supported. The Express middleware uses it for you; call it yourself to verify and settle from another server framework, or to drive settlement from a backend. The endpoints underneath are on Facilitator APIs.
npm install @chainsafe/x402-clientimport { FacilitatorClient } from "@chainsafe/x402-client";
// Construct once (it sends Authorization: Bearer <apiKey>) and reuse.
const facilitator = new FacilitatorClient(process.env.FACILITATOR_URL!, {
apiKey: process.env.FACILITATOR_API_KEY!,
});
const kinds = await facilitator.supported();
const verdict = await facilitator.verify(paymentPayload, paymentRequirements);
const settled = await facilitator.settle(paymentPayload, paymentRequirements);paymentPayload and paymentRequirements are the wire types from @chainsafe/x402-core.
Which requirements to send
Verify and settle against the requirements the payment was built for, its accepted, but only after checking them against your own terms: they are not signed, so a payer can echo anything. Compare at least the scheme, network, payTo, instrument and amount with what you quote, as the Express middleware does. The facilitator then holds the signed transfer to those requirements.
Answers and errors
verifyresolves with the verdict,isValidtrue or false; a refusal carriesinvalidReasonandextensions.detail. OneisValid: falseis not a refusal:invalidReason: "settlement_pending"means the payment was already relayed and may still commit, with the transaction inextra.transaction. Don't ask for a new payment.isSettlementPendingtakes only a settle answer, so checkinvalidReasonhere.settleresolves with the outcome on any2xx,successtrue or false. The facilitator answerssettlement_pendingand its other relay outcomes with200, so they arrive as values.settlement_pendingis not a failure: check it withisSettlementPendingfrom@chainsafe/x402-core, and see Pending payments.- Any other status throws a
FacilitatorErrorcarrying the HTTPstatus(0for a network failure or timeout), the response body, and theRetry-Aftervalue when there is one. A refusal before anything was relayed is a400, so it throws.
Error codes lists every reason code.
supported() and its cache
supported() returns what the facilitator settles: its (scheme, network) kinds, and in kinds[].extra the synchronizer, fee payer and instruments.
The answer is cached for supportedTtlMs (5 minutes by default). Concurrent callers share one request, and a refresh that fails falls back to the last answer rather than stopping you quoting. supported({ refresh: true }) skips the cache.