XRPL x402 v2 SDK (exact presigned Payment tx scheme)
npm install x402-xrplx402-xrplTypeScript SDK for x402 v2 payments over XRPL using the exact presigned Payment tx blob scheme from this repository.
This package is intended to mirror the ergonomics of the Python SDK (x402_xrpl/) so developers can easily build:
- Express x402-protected resource servers
- TypeScript buyer clients that automatically handle HTTP 402 Payment Required
``bash`
npm install x402-xrpl
If you are building a resource server:
`bash`
npm install express
`ts
import express from "express";
import { requirePayment } from "x402-xrpl/express";
const app = express();
app.use(
requirePayment({
path: "/ai-news",
price: "1000", // XRP drops; for IOUs use the XRPL value string (e.g. "1.25")
payToAddress: "rhaDe3NBxgUSLL12N5Sxpii2xy8vSyXNG6",
network: "xrpl:1",
asset: "XRP",
facilitatorUrl: "http://127.0.0.1:8011",
resource: "demo:ai-news",
description: "AI news feed (paid)",
}),
);
app.get("/ai-news", (_req, res) => res.json({ ok: true }));
app.listen(8080, () => console.log("listening on http://127.0.0.1:8080"));
`
- Set asset to a canonical XRPL currency code: 3 chars or 40-hex.RLUSD
- A symbol like must be provided as its 40-hex currency code, unless you explicitly opt into UTF-8 encoding using the currency helpers.issuer
- Provide the issuer as or extra.issuer.price
- Set to the IOU value string (e.g. "1", "1.25").
x402Fetch implements the standard x402 flow:
- Make request
- If 402 with accepts[], select a PaymentRequirementsPAYMENT-SIGNATURE
- Build
- Retry once
`ts
import { x402Fetch } from "x402-xrpl";
import { Wallet } from "xrpl";
const wallet = Wallet.fromSeed(process.env.XRPL_SEED!);
const fetchPaid = x402Fetch({
wallet,
wsUrl: "wss://s.altnet.rippletest.net:51233", // XRPL testnet websocket
networkFilter: "xrpl:1",
schemeFilter: "exact",
});
const resp = await fetchPaid("http://127.0.0.1:8080/ai-news");
console.log(resp.status, await resp.text());
`
From this package directory:
`bash``
npm install
npm run build
npm test