402, a real payment settles on testnet, and your endpoint shows up in the Bazaar catalog after that first settled payment. No registration step and no API key.
This guide uses @rail402.dev/sdk for the discovery listing and the stock @x402 packages for the paywall itself. Everything runs against the hosted facilitator at https://facilitator.rail402.dev.
Prerequisites
Node.js 20 or later (the packages target the current Node LTS), and a testnet account to receive payments (payTo).
Create and fund a payTo account with the Rail402 CLI:
G...) and secret. The receiver must trust the asset it is paid in,
so add a trustline to testnet USDC (CBIELTK6YBZJU5UP2WWQEUCYKLPU6AUNZ2BQ4WWFEIE3USCIHMXQDAMA) to
that account, for example in Stellar Lab. See
Stellar essentials for why the receiver needs one. (Or create and
fund an account by hand with friendbot.)
1. Install
Install the SDK for the listing and the stock@x402 paywall packages, pinned to 2.20.0.
@x402/hono for @x402/express@2.20.0. The route configuration object is identical.
2. Add the paywall and the listing
The middleware is stock@x402. The describeEndpoint call from @rail402.dev/sdk turns the paywalled route into a Bazaar listing by attaching discovery metadata under extensions.
- Hono
- Express
server.js
describeEndpoint returns the whole extensions value, already shaped as { bazaar: ... }. Its return type is branded, so wrapping it again as { bazaar: describeEndpoint(...) } is a compile error. That catches the most common cataloging mistake. See Get discovered.3. Start the server
4. See the 402
An unpaid request now returns a priced402 with the payment terms in the response:
5. Pay it
Cataloging is settlement-gated, so make the first payment yourself. The buyer needs a funded testnet account holding testnet USDC (get testnet USDC from the Circle faucet). The command-line wallet is the shortest path. CLI amounts are decimals, so--max 0.10 is 0.10 USDC.
6. Confirm it is cataloged
After the payment settles, search the Bazaar for words from your description:Try the whole loop
Theexamples/paid-api-agent example in the Rail402 repository runs a paid API that an agent discovers and pays, against testnet, in one command. It is the fastest way to watch verify, settle, catalog, and discover happen in sequence.
Next steps
Get discovered
Write parameter descriptions an agent can act on, and learn exactly what the facilitator catalogs and when.
Meter usage with upto
Bill for actual usage against a buyer-authorized ceiling instead of a fixed price.
Self-facilitation
Run verify and settle in-process, with no external facilitator and no network hop.
Preflight and testing
Catch a missing trustline or misconfigured payTo before a stranger’s payment fails on it.
When it fails
Every rejection carries a machine-readablecode and a non-null reason. A 402 that never settles, a listing that never appears, or a payment that is refused all report a code you can branch on. See Errors.