Payment rails

The two ways an Escro bot pays: the escrow rail for work that takes time and the x402 rail for a synchronous payment. Which rails your SDK enables, how to choose one, and what each refusal means.

Last updated · View as Markdown

A rail is the way a payment settles. @escro/sdk knows two, listed in its RAILS export: escrow and x402. If a refusal sent you here, jump to Refusals and how to fix them.

What a rail is

escrow rail x402 rail
What it is On-delivery settlement: Escro holds the USDC in a program-owned vault on Solana A direct payment (x402 exact) from the bot’s own wallet
Fits Work that takes time (async) A small synchronous purchase (sync)
Reached by createEscrow, or a 402’s on-delivery or job-escrow entry through pay() A 402’s exact entry through pay()
If the answer is poor or never comes The buyer’s code judges it; a missed deadline refunds The money moved with the request; nobody holds it back
Spend cap spendCap x402SpendCap
PaymentResult.reference The create_escrow signature The settlement’s transaction

The two rails are two tiers of trust, and they are complementary: x402 settles a paid request in one round trip, and Escro holds funds for asynchronous work. Escro never judges quality on either rail. On the escrow rail the buyer is the judge and the program only enforces the state machine. See Escro vs x402 for when each fits.

Which rails this SDK enables

RAILS names every rail the SDK knows. ENABLED_RAILS names the ones your installed build enables, and it is what every rail check reads. In @escro/sdk 0.5.0, ENABLED_RAILS is ["escrow", "x402"]. Earlier releases enable escrow only.

Read both from your own install:

import { RAILS, ENABLED_RAILS } from '@escro/sdk';

console.log(RAILS, ENABLED_RAILS);

The x402 rail uses the official x402 client. @escro/sdk depends on @x402/core, @x402/svm and @solana/kit at exact versions and loads them on the first exact payment, so a bot that never pays exact never loads them.

The escrow rail

The buyer locks USDC in an on-chain vault for a named worker. The worker claims the job, does the work and submits a deliverable. The buyer’s own code checks it, then releases payment or raises a dispute. If the buyer does nothing, the worker is paid 24 hours after submitting, into its USDC token account, which must already exist; if the worker misses the deadline, the buyer can be refunded.

  • Buyer: createEscrow, or pay() with a 402 that offers an on-delivery or job-escrow entry. The result carries escrow, the escrow’s address, for cancelEscrow and every later call.
  • Cap: spendCap ({ maxOutstandingMicroUsdc, outstanding? }) bounds the deposits locked in your open escrows, amount plus fee. A createEscrow on a mainnet client without it is refused (SPEND_CAP_REQUIRED).
  • Worker: serve a 402 menu with @escro/x402-middleware, or find assigned escrows by polling and claim them as in the worker bot guide.

The x402 rail

The bot pays an exact entry straight from its own wallet. The payment header goes once to the 402’s resource URL, never to a facilitator. Use it for small synchronous purchases, and escrow for work that takes time.

  • Buyer: pay() with a 402 whose exact entry matches your terms. An upto entry is never paid (unsupported_scheme).
  • Cap: x402SpendCap ({ maxMicroUsdc, spent? }) bounds what pay() spends over x402, separately from spendCap: neither draws on the other. It is per process and resets when the process restarts; give spent, a reader of what you have recorded as spent, to carry a budget across restarts. A payment counts in full before it is signed and is never credited back once signed. An exact payment on mainnet without it is refused (SPEND_CAP_REQUIRED), and one that would pass it is refused (SPEND_CAP_EXCEEDED).
  • Checks before signing: the official client builds the transaction, and the SDK’s guarded signer decodes it before the key signs: exactly one USDC transfer of your amount to your to, a fee payer that is not your wallet, and nothing else your wallet is named in.

How a buyer chooses

With the SDK

createEscrow is always the escrow rail. pay() reads the 402 and picks an entry:

  • Without a policy, pay() stays on the escrow rail when an on-delivery or job-escrow entry and an exact entry both match your terms, whatever order the 402 lists them in.
  • A 402 that lists only exact pays over x402.
  • A policy can choose exact instead. It can only narrow: the entry it returns must still match your to and amount.
import { Escro } from '@escro/sdk';

const client = new Escro({
  cluster: 'mainnet',
  rpcUrl,
  apiUrl,
  wallet,
  spendCap: { maxOutstandingMicroUsdc: 50_000_000 }, // escrow rail
  x402SpendCap: { maxMicroUsdc: 10_000_000 },        // x402 rail
});

const result = await client.pay({
  to: workerWallet,
  amountMicroUsdc: 5_000_000,
  url: 'https://worker.example.com/v1/summarise',
  request: { method: 'POST', body: JSON.stringify(input) },
});

console.log(result.rail); // "escrow" or "x402"

EscrowPaymentRouter.selectRail(tx) routes a payment by its shape. With no scheme, async work routes to escrow and sync work prefers x402, falling back to escrow when x402 is not enabled. With a scheme, on-delivery and job-escrow route to escrow under async, and exact and upto to x402 under sync. A scheme’s rail is never swapped for another: a rail that is not enabled is refused, not replaced.

With the kit

A bot made with create-escro-bot sets its rails in escro.config.ts:

rails: ["escrow", "x402"],
x402SpendCapUsdc: 1,
  • rails lists the rails the bot may use and defaults to ["escrow"].
  • List x402 and the bot’s x402SpendCap is x402SpendCapUsdc, which defaults to 1 USDC. Leave it out and the x402 rail is a zero budget: pay() over x402 is refused, on every cluster.
  • rails does not gate the escrow rail, whose cap stays spendCapUsdc (amount plus fee across open escrows).
  • The budget is for one process run: it does not refill while the process lives and a restart resets it. The bot prints which budget is in force at every start. To carry a budget across restarts, give spent in src/bot.ts.
  • Nothing in the scaffold pays exact: your own client.pay() does, and hire402 stays on on-delivery.

The config is checked when it loads, against the installed SDK’s ENABLED_RAILS, so a rail the SDK does not enable stops the bot at start, before any escrow.

How a worker chooses

A worker is paid on the escrow rail by default, and over x402 only through exact entries it configures: entries it verifies itself, or a settleExact price the middleware settles through its facilitator. @escro/x402-middleware serves an x402 402 menu from your HTTP server: each route answers an unpaid request with a 402 offering the on-delivery escrow entry, beside any exact entries you configure. The buyer funds the escrow and presents it, the middleware claims it with your own Escro client, you do the work and submit, and the buyer releases. A kit worker serves the same menu through serve402 in escro.config.ts, off by default.

exact entries are route configuration, placed after the on-delivery entry. Entries passed as exact are never verified by the middleware. A payment of a scheme the route configures reaches your next handler untouched, so configuring an exact entry is your assertion that an exact verifier is mounted after the middleware. A route’s settleExact price is different: the middleware verifies and settles it through the facilitator you configure. A buyer’s SDK without a policy pays the on-delivery entry when both match.

The kit worker’s escro.config.ts carries the same rails list, defaulting to ["escrow"] and checked the same way at load.

Refusals and how to fix them

Both refusals end with a link to this page.

The SDK refusal

Payment rail "<rail>" is not available in this installation. See https://escro.ai/rails

@escro/sdk throws EscroRailNotEnabledError (code ESCRO_RAIL_NOT_ENABLED); its rail field names the rail. It means one of two things:

  • The x402 packages did not load. pay() throws it for the x402 rail when @x402/svm or a package it needs fails to load, and the error’s cause is the load failure. Nothing was signed and nothing was counted against x402SpendCap.
  • The rail is not enabled in this build. pay() and EscrowPaymentRouter.selectRail throw it when the entry or scheme you are paying routes to a rail missing from ENABLED_RAILS.

To fix it:

  1. Read err.cause. If a package failed to load, reinstall so @x402/core, @x402/svm and @solana/kit resolve at the versions @escro/sdk pins, on Node 22 or later.
  2. Check ENABLED_RAILS in your install. If it lacks the rail, upgrade @escro/sdk (the x402 rail is enabled from 0.5.0), or pay an entry on a rail it enables, such as the 402’s on-delivery entry.

The kit refusal

Payment rail "<rail>" is not enabled in this @escro/sdk. Enabled: <enabled rails>. Remove it from "rails". See https://escro.ai/rails

The bot’s escro.config.ts lists a rail in rails that the installed @escro/sdk does not enable. The config check runs at load, so the bot stops at start and nothing is created or paid.

To fix it, remove the rail from rails, or upgrade @escro/sdk to a version whose ENABLED_RAILS lists it. A name that is not a rail at all (not in RAILS) fails the config schema before this check, with the schema’s own message.

Refusal Means Fix
EscroPayError unsupported_scheme The scheme is not one Escro routes, or it is upto Pay an on-delivery, job-escrow or exact entry
EscroPayError scheme_conflict scheme differs from the entry’s scheme, or the mode is not the scheme’s (escrow is async, x402 is sync) Pass the entry’s own scheme and its mode
SPEND_CAP_REQUIRED A mainnet createEscrow without spendCap, or a mainnet exact payment without x402SpendCap Set the cap for that rail
SPEND_CAP_EXCEEDED Escrow: the deposit (amount plus fee) would take your open escrows past spendCap. x402: the payment would pass x402SpendCap Escrow: raise maxOutstandingMicroUsdc or wait for open escrows to settle. x402: raise maxMicroUsdc: a spent budget does not refill while the process runs

Escro runs no marketplace and picks no worker: the buyer names the worker, through its own discovery or the worker’s own 402, and the buyer’s code decides whether the work is accepted.