LOPWDocumentation

Docs / Guides

Add a warranty to an x402 API

Turn an existing x402 endpoint into a bonded one. Six steps; the detailed code is in Getting started for sellers.

  1. Create a dedicated Ed25519 signing key for the service (signingKeyFromSeed, publicKeyHex) and store its seed as a server secret.
  2. Pick the predicates you can honour and set their limits (guide). Every parameter is part of the hashed terms.
  3. Register the service: binding.registerService(seller, signingKey, terms, minStake), or register_service(seller, signing_key, terms, min_stake) on the registry. Keep the returned service_id.
  4. Deposit at least 100 USDC: binding.deposit(seller, serviceId, amount). When stake reaches min_stake the service turns Active.
  5. Register the lopw extension on your x402 resource server (createLopwExtension, registerExtension), add lopwRequestContext() before paymentMiddleware, and enable it on each route with extensions: { lopw: {} }.
  6. On routes that promise freshness (P3), set DATA_AS_OF_HEADER to the Unix time your data was true as of. On routes that promise P6, set ORACLE_EVIDENCE_HEADER.
TypeScript
const lopw = createLopwExtension({ binding: new StellarBinding(network), serviceId, signingSeed, maxClaim: 5n * 10_000_000n });
const server = new x402ResourceServer(new HTTPFacilitatorClient({ url: facilitatorUrl }))
  .register(network.caip2, new ExactStellarScheme())
  .registerExtension(lopw);
app.use(lopwRequestContext());
app.use(paymentMiddleware({ "GET /v1/quote": { accepts: [{ scheme: "exact", price: "$0.01", network: network.caip2, payTo, maxTimeoutSeconds: 60 }], extensions: { lopw: {} } } }, server));

The middleware only issues offers while the service is Active. If stake drops below the minimum, routes fall back to plain x402 terms until you deposit again. It only issues receipts for offers it signed itself, and only after the facilitator reports a successful settlement.

Check your work

  • GET your route without payment: the 402 body’s extensions.lopw.info carries version, network, registry, service_id and a base64 offer.
  • Pay it with the buyer SDK: warranty.problems is empty and warranty.breaches is empty.
  • Read the service over the public API: state Active, stake as expected.