exact, a fixed price, and upto, a cap the buyer signs of which the seller settles what the call
used.
The exact payment loop
1
The seller asks for payment
The buyer requests a paid route. The seller answers
402 Payment Required with a PAYMENT-REQUIRED
header that lists what it accepts: scheme exact, network stellar:testnet, the asset’s contract
address, the payTo address, the amount in the asset’s base units, maxTimeoutSeconds, and
extra.areFeesSponsored: true, which the seller’s scheme reads from Rail402’s /supported.2
The buyer signs an authorization
The buyer’s x402 client builds a Soroban invocation of the asset contract’s
transfer(from, to, amount)
and signs its authorization entry with the buyer’s key. The signature fixes the asset, the recipient and
the amount. The client sends the payment as payload: {transaction} in the PAYMENT-SIGNATURE header.3
The seller calls /verify
Rail402 runs its own checks first, before any simulation: protocol, operator policy, transaction shape,
accounts, authorization and expiry. It then runs the unmodified
@x402/stellar verifier, which simulates
the transaction against the current ledger. When simulation fails, Rail402 names the on-chain cause, for
example a missing trustline or a spent nonce.4
The seller calls /settle
Rail402 runs its own checks again, claims the payer’s authorization and leases one of its channel
accounts. Upstream
@x402/stellar then runs its verifier again and rebuilds the transaction around the
buyer’s signed authorization with the channel account as the source, and Rail402’s sponsor account wraps
it in a fee bump and pays the fee. Rail402 records the signed envelope before broadcasting it, then waits
for the ledger.5
The seller serves the resource
The settle response carries the transaction hash. The seller returns it to the buyer in the
PAYMENT-RESPONSE header together with the resource.The upto payment loop
upto follows the same loop with three differences; upto payments has the details.
1
The seller names a cap and a settlement authority
The
upto option’s amount is the cap, and extra.facilitatorAddress names the facilitator’s settlement
authority, which the seller’s scheme copies from /supported.2
The buyer signs terms, not a transfer
The buyer signs one authorization entry for
settle(terms) on the upto settlement contract: the
recipient, token, cap, settlement authority and an expiration ledger, with one nested
token.approve(payer, settlement contract, cap, expiration). /verify simulates the settlement for the
full cap.3
The seller settles what it used
After serving, the seller names the amount, from zero to the cap, and calls
/settle. Rail402 submits
settle(payer, terms, amount) with the settlement authority as the operation source; the contract checks
the buyer’s terms, the authority’s authorization and 0 ≤ amount ≤ cap, and pulls exactly the amount from
the buyer to payTo. The sponsor pays the fee through a fee bump, as for exact./health reports their remaining TTL (upto contract).
What the facilitator can and cannot do
Rail402 is non-custodial. It holds one secret per network, the sponsor seed, and derives two kinds of account from it: its channel accounts and, whenupto is served, one settlement authority.
- The sponsor pays every settlement fee and the base reserves of the channel accounts and the authority. It needs only XLM.
- Channel accounts are the source accounts of settlement transactions, one settlement at a time each, so concurrent settlements never compete for a sequence number. They hold no balance.
- The settlement authority holds no funds either. It is the operation source of
uptosettlements, so it chooses the settled amount between zero and the cap the buyer signed, or declines to settle; it cannot exceed the cap, change the recipient or token, reuse an authorization or move anyone’s funds. - Verification refuses any payment in which a facilitator account (the sponsor, a channel account or the
settlement authority) is the payer or a party to one of its authorizations, and an
exactpayment whose transaction or operation source is one; anuptopayment’spayTomay not be a facilitator account either. - For
exact, the payer’s signature covers the asset, recipient and amount. Forupto, it covers the asset, recipient, cap, settlement authority and expiration. Changing any of them after signing fails signature verification.
Settlement is idempotent and crash-safe
Each settlement is keyed by the payer’s authorization (network, payer, nonce).- A repeated
/settlefor the same payment returns the recorded result, and funds move once. The ledger is consulted first, so this holds even after the authorization expired or while the sponsor guard refuses new settlements. The repeat is marked for the seller inEXTENSION-RESPONSES(rail402.settlement:repeat,settledBy, andattempt, the attempt id the request holding the settlement’s claim when the repeat is answered carried inextensions.rail402.settlement.attempt: the one that started it, or the one that took its stale claim over. A seller can tell its own attempt’s settlement from another’s). - A different request for an authorization already held (another envelope, recipient, asset or
amount) is refused (
settle_exact_stellar_idempotency_conflict, orsettle_upto_stellar_idempotency_conflictfor anuptosettlement asked for another amount). - If the transaction is not final within the confirmation window,
/settleanswerssettlement_pendingwith the transaction hash, and a background reconciler finishes it from the recorded bytes. - After a crash or restart, only the recorded bytes are ever resubmitted, so there is never a second transaction for the same authorization.
The Bazaar
A payment can carry the x402bazaar extension, which describes the paid resource: its input and output
schema, method or tool name, and service metadata. When a payment with that extension settles, Rail402 adds
the resource to its catalog, provided the metadata is valid and, for an http or https resource URL, the
host is public. A payment without the extension is settled normally and not cataloged.
- Settlement-gated. Nothing is listed without a settled payment to it.
/verifyonly previews the outcome. - Bound to the payee. The listing belongs to the
payTothe settlement paid. Another seller cannot change it. - Confirmed at the origin. An HTTP resource is listed, and any change to it published, only after the
resource’s own
402response confirms it. - Off the payment path. Cataloging never changes the payment result and adds no transaction. The seller
learns the outcome from the
EXTENSION-RESPONSESheader of the facilitator’s response. uptolistings. Anuptoresource is listed at its cap, the most a call can cost. A settlement of zero, on chain or off, never creates or changes a listing: a listing needs a settlement that moved value to itspayTo(cataloging rules).
GET /discovery/resources and
GET /discovery/search. The catalog lives in Postgres, not on-chain.
Networks
Rail402 knows the CAIP-2 networksstellar:testnet and stellar:pubnet. Which ones an instance serves is
configuration (NETWORKS). The hosted instance serves stellar:testnet
only. The tests and conformance runs exercise testnet. Pubnet can be configured, with stricter rules that
the service checks at startup (see Configuration), but it has not been exercised end to
end.
Components
Rail402 is one service backed by Postgres, built from workspace packages that can also be used on their own.
Without Postgres (
STORE=memory) the same service runs in one process with no durable state, which suits
local development and tests. See Configuration.
The service also runs background tasks: the reconciler that finishes unconfirmed settlements, the network
poll behind /health and /ready, the upto settlement authority’s provisioning, the contract TTL monitor
and keeper, and the Bazaar’s origin checks and search indexing.
Buyers and agents can use the stock x402 clients, or the agent tools built on them: the buyer SDK
(packages/sdk), the MCP server (packages/mcp) and the CLI (packages/cli). They discover resources
through the Bazaar, pay under a spending policy, and reach sellers through packages/safe-fetch, which
refuses private addresses and pins DNS (Agents).