Skip to main content
@rail402.dev/facilitator is the settlement engine the service runs. A resource server can run it in its own process and call it through inProcessClient, a stock x402 FacilitatorClient. Verification and settlement run the same checks with the same codes as over HTTP (stages 1 to 8 of Errors and verification rules), without the network hop. The HTTP request checks (stage 0) and the Bazaar are part of the service and are not included. The seller then holds a sponsor seed and pays its own settlement fees. Use this when you want no dependency on an external facilitator; otherwise point HTTPFacilitatorClient at a Rail402 instance.
The package runs on Node.js 24.11 or later. For durable settlement across processes, add @rail402.dev/store-postgres (see Options).

Example

An @x402/express seller that settles its own payments on testnet. The seller’s dependencies are the same as in the seller quickstart, plus @rail402.dev/facilitator:
server.ts
SPONSOR_SECRET is the seed of a funded testnet account and PAY_TO an account with a USDC trustline. The buyer quickstart’s create-account.ts, run with no amount, creates either: a Friendbot-funded account (the sponsor needs only its XLM) with a USDC trustline. The stock buyer from the buyer quickstart pays this server unchanged.

Options

createStellarFacilitator({ networks, log, observer }) takes one entry per network. The optional observer is a SettlementObserver that receives each settlement’s channel lease wait, submissions, final state, fee charged, reconciliation outcome, the number of unresolvable settlements after each reconciliation pass, and repeats, for your own metrics; the service’s Prometheus metrics are built on it (apps/rail402/src/metrics.ts). The in-memory ledger and channel pool suit one process that can lose its state on restart. For durable, multi-process settlement, pass the Postgres stores the service itself uses, from @rail402.dev/store-postgres (PostgresSettlementLedger, PostgresChannelPool, createDatabase, migrate); see apps/rail402/src/runtime.ts for how the service wires them. Before serving upto with a contract of your own, check that it is live and runs the WASM you configured: await assertUptoContract(server, contract, contractWasmHash) throws UptoContractCheckError (reason absent or wasm_mismatch) otherwise. The contract has no admin and cannot be upgraded, so this one check pins what every upto payment runs. The Rail402 service runs it at startup and refuses (or, with several networks, holds) pubnet when the contract is absent or runs other code.

Access, limits and service fees

The service’s access keys, request limits and metering are HTTP features. In-process, the facilitator runs inside your server, so your server authenticates its own callers, and the facilitator gives it the same settlement controls the service uses: who a settlement is for, how much each caller and the network may cost the sponsor, how fast one payer may settle, which tokens are accepted, and the service fee recorded with each settlement. Request rate limits on your routes (per address or per credential) stay your server’s, as for any other route.
withCaller covers every settlement started inside its callback, including through awaited calls. Bound the sponsor with a guard on every network you serve; pubnet refuses to start without one. packages/facilitator/test/in-process-controls.integration.test.ts exercises each control above against a local network.

Startup checks

createStellarFacilitator refuses a setup by throwing FacilitatorSetupError, whose code is stable (the same code as the service’s startup check for the same setting, where there is one) and whose message names the field to set: Other malformed values (a channel count below 1, an invalid seed, a non-canonical upto contract without its WASM hash) throw a plain Error naming the field.

What you give up

  • Bazaar. Cataloging and discovery live in the Rail402 service, not in the facilitator package. An in-process facilitator does not catalog resources.
  • Operations. Readiness checks, metrics, the sponsor balance polling and the upto contract’s TTL keeper are part of the service. Monitor the sponsor’s balance yourself (and feed it to SponsorBudget), and run facilitator.reconcile() at startup and periodically, as the example does.
An in-process facilitator has no dependency on Rail402’s hosted service: it talks to the Stellar RPC you configure, and the upstream @x402/stellar verifier reads its ledger-time estimate from public Horizon (falling back to 5 s when Horizon cannot be reached). Its integration tests run with every request to a rail402.dev host refused.