@rail402.dev/scheme-upto-stellar
v0.1.0
Published
The upto scheme for Stellar: client, server and facilitator, backed by the x402 upto settlement contract.
Readme
@rail402.dev/scheme-upto-stellar
The upto settlement scheme for Stellar. A buyer authorizes a ceiling and only the actual usage
settles, which fits metered services such as token billing or per-call APIs. A Soroban contract
enforces the ceiling and single settlement on-ledger. (exact charges a fixed price; upto charges
"authorize up to N, settle what was used".)
What you need
Node.js 20+, testnet only. Registration is the same as the exact scheme, so you also use a stock
x402 client, a @x402/stellar signer, and a facilitator that supports upto.
Install
npm install @rail402.dev/scheme-upto-stellarBuyer side
Register the scheme on a stock x402 client:
import { x402Client } from "@x402/core/client";
import { wrapFetchWithPayment } from "@x402/fetch";
import { createEd25519Signer } from "@x402/stellar";
import { UptoStellarClientScheme } from "@rail402.dev/scheme-upto-stellar";
const signer = createEd25519Signer(process.env.STELLAR_SECRET, "stellar:testnet");
const client = new x402Client();
client.register("stellar:*", new UptoStellarClientScheme(signer));
const res = await wrapFetchWithPayment(fetch, client)("https://metered.example/tokens");Facilitator side
import { UptoStellarFacilitatorScheme } from "@rail402.dev/scheme-upto-stellar";
facilitator.register("stellar:testnet", new UptoStellarFacilitatorScheme(signers));Sellers register UptoStellarServerScheme on their x402ResourceServer.
Exports: UptoStellarClientScheme, UptoStellarServerScheme, UptoStellarFacilitatorScheme,
UPTO_CONTRACTS, uptoContractFor.
Part of Rail402. Apache-2.0.
