Skip to Content
KryptWarden Developers
Guides

Sell over x402

Charge KryptWarden agents (and any x402 client) for your API.

KryptWarden agents pay standard x402 challenges, so you don't need anything KryptWarden-specific to get paid. Any x402 seller on Stellar works. This guide shows the setup the demo sellers use.

What you need

  • A Stellar address to be paid at, with a USDC trustline (USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5 on Testnet). Without one, the transfer fails and the payment rolls back.
  • A facilitator that can settle Soroban custom-account payments. On Testnet you can use https://pay.kryptwarden.xyz.

Why the facilitator matters

A KryptWarden payment runs the wallet's __check_auth, which costs more than a plain account's signature check. Facilitators with a low fee ceiling (often 50,000 stroops) reject these payments at simulation. KryptWarden's facilitator allows up to 2,000,000 stroops.

An Express seller

npm install express @x402/express@2.32.0 @x402/core@2.32.0 @x402/stellar@2.32.0
server.ts
import express from "express";
import { HTTPFacilitatorClient } from "@x402/core/server";
import { paymentMiddlewareFromConfig } from "@x402/express";
import { ExactStellarScheme } from "@x402/stellar/exact/server";

const NETWORK = "stellar:testnet";
const PAY_TO = process.env.SELLER_ADDRESS!; // your G… address, with a USDC trustline

const app = express();
app.use(express.json());

const facilitator = new HTTPFacilitatorClient({ url: "https://pay.kryptwarden.xyz" });

app.use(
  "/paid",
  paymentMiddlewareFromConfig(
    {
      "GET /weather": {
        accepts: { scheme: "exact", price: "$0.05", network: NETWORK, payTo: PAY_TO, maxTimeoutSeconds: 90 },
        description: "Weather for one city",
      },
    },
    facilitator,
    [{ network: NETWORK, server: new ExactStellarScheme() }],
    { appName: "My Weather API", testnet: true },
  ),
);

app.get("/paid/weather", (req, res) => {
  res.json({ city: req.query.city ?? "Lagos", tempC: 31 });
});

app.listen(4030);

Route keys are relative to where the middleware is mounted: GET /weather under /paid protects /paid/weather.

Test it with an agent

  1. Add your PAY_TO address as an allowed seller on a test agent (Register an agent).
  2. Call it:
const res = await kw.fetch("http://localhost:4030/paid/weather?city=Accra");
console.log(await res.json());

The payment shows up in the owner's Spend Ledger under your address. Ask the owner to give it a readable name through the agent metadata endpoint (sellerAliases).

Pricing tips

  • Price per call, small. Calls under the agent's auto-approve limit settle with no human involved. Anything above becomes a hold and waits for the owner.
  • Keep the price stable between the challenge and the retry. For held payments the SDK compares the new challenge with the approved hold and refuses if the amount, recipient or asset changed.

On this page