Requires Node.js 24, which runs the
.ts files below directly. Every package version matches what Rail402
is tested against.1. Install
@stellar/stellar-sdk on the version @x402/stellar uses. Two copies of the SDK’s XDR classes in one
process break signing in ways that only show up at runtime.
2. Create a funded testnet account
The buyer’s account needs a USDC trustline and some testnet USDC. This script creates an account with Friendbot, adds the trustline and, when given an amount, buys that much USDC from the testnet XLM/USDC pool, the same way Rail402’s conformance run does.create-account.ts
export BUYER_SECRET=S...
3. Pay
buyer.ts
wrapFetchWithPaymentFromConfig sends the request, and on a 402 it picks the seller’s exact /
stellar:testnet option, signs the transfer authorization with the buyer’s key and retries with the
PAYMENT-SIGNATURE header. The stock default spend controls apply.
Point it at any x402 seller on stellar:testnet. To have one, run the
seller quickstart in another terminal; it listens on localhost:4021.
transaction is the settlement on the testnet; look it up at
https://stellar.expert/explorer/testnet/tx/<transaction>. The network fee is paid by the facilitator’s
sponsor, not the buyer: the recorded canonical client run shows the
buyer’s USDC balance falling by exactly the price and the seller’s rising by the same amount.
Find something to buy
Resources that sellers have been paid for through Rail402 are listed in its Bazaar:apps/demo-seller), whose
listings are paid through the hosted facilitator. Each result carries its resource URL, its accepts payment options
and the bazaar info that describes its input and output. See Search.
When a payment is refused
When the facilitator refuses a payment, the seller does not serve the resource. Rail402 always names the reason with a stable code and a non-empty message, for exampleinsufficient_funds when the balance is too
low by the time the payment is verified, or invalid_exact_stellar_payload_payer_trustline_missing when the
buyer has no trustline for the asset. The full list is in Errors and verification rules.