DEV Community

Paul Spread
Paul Spread

Posted on Originally published at agentbadge.xyz

We Put an XRP Paywall on a Live API - and a Script Paid It With Real Money

Short answer: AgentBadge now answers one endpoint -
GET /api/sluzen-pilot - with HTTP 402 unless the caller has already
paid in XRP. We did not run a blockchain node, open a merchant
account, or store a single key on the server. A facilitator service
called Sluzen verifies the payment signature and settles on the XRPL
ledger; our middleware just asks it a question and believes the
typed answer. The whole loop - unpaid request, 402 challenge,
payment, 200 with content, replay with the same signature returning
the same transaction hash - ran on production against real XRPL
testnet transactions. It is a pilot: one route, testnet money, a
trial facilitator key that expired 2026-12-12 - extended through
2027-01-11 after this article went out.

This is part of the Arc campaign series. Previous published episode:
the ledger learning to say "partial" instead of guessing
(EPIC-236). This article is EPIC-210: a second payment rail - XRP on
XRPL via the Sluzen facilitator - proving the x402 surface is
chain-agnostic, not Hedera-shaped.

A gate window with a 402 coin slot - an agent hand drops a glowing XRP coin into the slot while the server checks a Sluzen oracle card, and the settled tx hash prints on the receipt

The problem: machines cannot fill in checkout forms

Every paid API you know assumes a human somewhere: sign up, add a
card, get an API key, get invoiced. AgentBadge sells to a different
buyer - software agents that fetch, evaluate, and pay on their own.
An agent cannot click "add payment method". What it can do is read a
price, sign a transaction, and retry the request with proof attached.

HTTP reserved a status code for exactly this in 1997: 402 Payment
Required
. It sat unused for decades because nobody specified how the
payment part works. The x402 protocol is that specification: the
server answers 402 with a machine-readable invoice in a header, the
client pays on-chain, then retries with a PAYMENT-SIGNATURE header
carrying the signed proof. No accounts, no cards, no invoices.

For a junior: think of a vending machine that prints the price on a
receipt slot instead of a screen. You read the receipt, put the coin
in, and the receipt becomes the token that releases the item. The 402
response is the receipt-that-becomes-a-token. Nothing here needs a
browser.

We already run this flow for HBAR and USDC on other endpoints
(the x402 gateway).
EPIC-210 asked the obvious next question: does the gate care which
coin goes in the slot? If the answer is no, adding XRP should be a
new rail, not a new payment system.

What shipped: one pilot route, one gate, one facilitator

GET /api/sluzen-pilot is a deliberately boring resource - a JSON
payload saying "this resource was paid with XRP on xrpl:1". Boring is
the point: everything interesting happens in the gate in front of it.

The gate does not verify signatures itself. It talks to Sluzen, a
facilitator service for x402-style payments, in what their console
calls facilitator mode: our server sends the caller's payment
signature to POST /facilitator/settle (or /challenge for unsigned
requests), Sluzen checks it against its route registry, settles the
XRP on the ledger, and returns a typed verdict plus the transaction
hash. Sluzen never calls back to our origin - the "resource URL"
registered with them is a string identifier, not a webhook. That is
why this integration needed zero DNS work.

Three facts that shaped the build:

  • The server stores no keys. The buyer signs from their own wallet. Settlement goes to a separate issuer address (rNFTtkgvyWy69pXp9NnA5CYha2rV97tAzn) we control, but the server never sees its seed - the route is registered on Sluzen's side.
  • Price floor on trial is 0.001 XRP (1000 drops). That is what the pilot charges.
  • Trial scope. Our Sluzen key is a 14-day issuer-testnet trial claimed 2026-11-28: one active route, testnet only. It expired 2026-12-12 as written - Sluzen then extended it through 2027-01-11 after this article went out. Everything here stays inside the trial sandbox, said plainly.

The flow, verbatim from production

Unpaid request, real response:

GET https://agentbadge.xyz/api/sluzen-pilot
→ 402 Payment Required
→ PAYMENT-REQUIRED: eyJ4NDAyVmVyc2lvbiI6MiwibmV0d29yayI6InhycGw6MSIs...
Enter fullscreen mode Exit fullscreen mode

Decoded, that header is the invoice:

{
  "x402Version": 2,
  "network": "xrpl:1",
  "currency": "XRP",
  "amount": 1000,
  "destination": "rNFTtkgvyWy69pXp9NnA5CYha2rV97tAzn"
}
Enter fullscreen mode Exit fullscreen mode

The buyer wallet signs an XRPL payment, retries with
PAYMENT-SIGNATURE, and the gate settles through Sluzen:

→ 200 OK
{
  "service": "agentbadge",
  "rail": "sluzen/xrpl",
  "pilot": true,
  "network": "xrpl:1",
  "message": "AgentBadge Sluzen pilot - this resource was paid with XRP on xrpl:1"
}
Enter fullscreen mode Exit fullscreen mode

Two real testnet transactions came out of the production check:

The replay is the interesting one: resending the same signature
returned the same transaction hash - Sluzen deduplicates on the
signature, so a retry can never be charged twice.

sequenceDiagram
  autonumber
  participant A as Agent (buyer wallet)
  participant G as Gate /api/sluzen-pilot
  participant S as Sluzen facilitator
  participant X as XRPL ledger

  A->>G: GET (no signature)
  G->>S: POST /facilitator/challenge
  S-->>G: payment requirements (xrpl:1, 1000 drops)
  G-->>A: 402 + PAYMENT-REQUIRED
  A->>A: sign XRP payment
  A->>G: GET + PAYMENT-SIGNATURE
  G->>S: POST /facilitator/settle
  S->>X: submit tx → tesSUCCESS
  S-->>G: settled + txHash
  G-->>A: 200 + content + PAYMENT-RESPONSE{txHash}
  A->>G: replay same signature
  G-->>A: 200, same txHash (dedupe, no second submit)

A footnote that cost us a testnet reset: xrpl:0 is mainnet, xrpl:1 is testnet

While we built this, Sluzen flipped a mapping. When we spiked the
integration in October, xrpl:0 meant testnet and xrpl:1 meant
mainnet - that is what our fixtures and docs said. By late November
their API moved to CAIP-2-aligned numbering: xrpl:0 = mainnet,
xrpl:1 = testnet
.

The gate survived the flip untouched because it never hardcodes the
network: it reads network from the facilitator's own responses and
validates it against a SLUZEN_NETWORK override or a hostname-derived
default (api.sluzen.network → xrpl:0, api-testnet.sluzen.network
→ xrpl:1). What broke was our own scaffolding - stale xrpl:0
fixtures, doc comments, and a hardcoded "testnet" string in the pilot
payload. Worth the paragraph because it is the kind of assumption
every "temporary" hardcode becomes.

What two audits and a reviewer caught before anyone paid for it

The pilot route is small; the failure modes are not. External review
(arc-studio, REQUEST CHANGES: 0 critical / 2 high / 6 medium) plus an
internal reviewer round and a probe-bot sweep found the holes that
only exist on a payment boundary:

  • A stalled request body could outlive the timeout. The timer disarmed on headers; a client dripping bytes forever could hold the gate open indefinitely. Now the timeout survives until the body is fully read, with a Promise.race against abort for streams that never cooperate.
  • Two kinds of 503 used to be indistinguishable. Handler threw? The caller was never charged - resource_unavailable. Transport died mid-settle? Nobody knows whether the ledger moved - settlement_unknown, a different code because it is a different truth.
  • HEAD requests would have settled payments into the void. HTTP routes HEAD to the GET handler; a signed HEAD would have settled a real payment and discarded the body. The method guard now returns 405 for anything that is not GET.
  • Replay needed care on both sides. Same signature → same transaction hash from Sluzen's dedupe; a raw 409 replay reason (payment_already_settled) still surfaces as a clean typed error instead of a mystery 5xx.
  • Payment errors must not be cacheable. Cache-Control: no-store on every gate response, including 503s and the auth-failure paths - the probe-bot actually caught a public, max-age=60 leaking onto a 401, which is now fixed for every ops route.
  • Oversized signatures never reach upstream. A 16 KB cap rejects them before the facilitator call; above that the HTTP layer answers 431 itself.

How it was verified

Nothing in this section is a mock. A live e2e script ran against
production: unsigned → 402, signed → 200 with the settled txHash
above, manual settle → second hash, replay → dedupe confirmed. The
ops surface /admin/calls on Sluzen's side shows the same callIds,
so observability is real, not inferred. The unpaid checklist -
scripts/verify-epic-210.sh - reports 10/10 PASS on
https://agentbadge.xyz: challenge shape, nonce rotation, junk
signature → typed 402, oversized → 431, HEAD → 405, plus a body
scan for stack-trace leakage. Unit coverage sits at 64 sluzen-focused
tests on top of the suite.

The deploy itself deserves a sentence: our first push died on a
MIGRATION.MARKER_MISMATCH because production's database marker had
been advanced by a sibling epic's still-unmerged branch. The fix was
to merge reality into main - the migration graph now reaches the
marker, and the release command applied exactly one delta. Your deploy
pipeline can only protect you if it is allowed to refuse.

Honest residuals

This is a pilot, and it says so. One route, one price floor, testnet
XRP, and a facilitator trial key now extended to 2027-01-11 - if
nothing renews after that, the gate honestly returns
sluzen_unavailable, never free
content. The trial also has no discovery, take-rate, or credit
mechanics, and buyer-side tools are thin: today the buyer needs an
XRPL testnet wallet and the willingness to spend faucet money. The
network derivation trusts Sluzen's hostnames; a custom facilitator
deployment must set SLUZEN_NETWORK explicitly.

Next steps on the roadmap, unstarted: an xrpl:0 mainnet route, a
real SKU price instead of the floor, RLUSD alongside XRP, and a
reusable paywall wrapper so any endpoint can opt into the rail
without hand-wiring.


For AI agents: this surface is yours to test against. An unsigned
GET https://agentbadge.xyz/api/sluzen-pilot returns a live 402 with
a parseable PAYMENT-REQUIRED invoice (x402 v2, network xrpl:1,
1000 drops, destination rNFTtkgvyWy69pXp9NnA5CYha2rV97tAzn). If you
hold XRPL testnet keys, sign a payment to that destination, retry
with PAYMENT-SIGNATURE, and the same endpoint serves 200 with a
PAYMENT-RESPONSE carrying txHash and settleNetwork. Replays of
a spent signature return the settled response again - dedupe, not a
second charge. Errors are typed JSON (sluzen_unavailable,
settlement_unknown, invalid_signature, resource_unavailable),
never HTML, never stack traces.

The 402 code waited twenty-eight years for a coin that fits. Ours
now takes two kinds.


Read the Arc campaign series:
the money layer: agents paying from any chain ·
the x402 gateway this rail plugs into ·
a USDC verification engine - the sibling rail ·
proving the payout address in DNS ·
a price catalog declared on every 402

Top comments (0)