nodox x402

Paid APIs without one income stream

x402 lets an API answer "402 Payment Required" and get paid in the retry. With nodox, each payer pays a normal Solana address that only the seller's view key can recognize, so the seller's API income does not show up as one public stream.

01Ten lines for an existing x402 server

@nodox/x402 plugs into the official x402 server SDK (@x402/hono, @x402/express) and replaces a fixed payTo with a nodox one-time address made from your meta-address.

server.ts@nodox/x402
import { nodoxPayTo } from "@nodox/x402";

const payTo = nodoxPayTo({
  metaAddress: process.env.NODOX_META_ADDRESS!,       // from the nodox app
  rotationSecret: process.env.NODOX_ROTATION_SECRET!, // 64 hex characters, keep it secret
  apiBase: process.env.NODOX_API!,                    // the nodox server
  mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
});
const facilitator = new HTTPFacilitatorClient({ url: `${process.env.NODOX_API}/x402` });
app.use(paymentMiddleware({ "GET /weather": { accepts: { scheme: "exact", network: SOLANA_MAINNET, payTo, price: "$0.01" } } },
  new x402ResourceServer(facilitator).register(SOLANA_MAINNET, new ExactSvmScheme())));

generateRotationSecret() makes the secret. A ready-made Hono version is nodoxPaywall({ network, apiBase, metaAddress, rotationSecret, routes }). Buyers need nothing new: any x402 client pays. A client that sends x-nodox-payer: <its wallet> gets its own address for the hour; nodoxFetch() and the MCP tool x402_fetch do that.

On first use of an address, before answering the 402, the middleware asks the facilitator to create its token account and, if the log does not know the address yet, announces it with an encrypted note {kind: "x402", route, payer} that only the seller's app can read.

02Which address a payer gets

CaseAddress
Same payer within one windowthe same address
Window length60 minutes by default, aligned to UTC
Next window, another payer, another seller secreta different address
No payer header, or not a Solana addressthe window's shared anonymous address
More than 50 payers in one windowlater payers share the anonymous address
Paid retry right after the window flippedthe previous address is accepted for 5 minutes

The address is a pure function of the request, as x402 needs (the 402 and the paid retry must name the same payTo): r = SHA-512("nodox-v1/x402" ‖ secret ‖ window ‖ payer) mod ℓ, then the normal nodox one-time address for that r. One address per payer per hour instead of per request saves a new token account each time.

03The facilitator

The nodox facilitator runs the official @x402/svm exact scheme (instruction, signature, amount and recipient checks, simulation, a guard against settling twice) with the relayer as fee payer, and serves only nodox addresses. It prepays the token account of each new address; that rent comes back when the seller moves the money out through the nodox relay, which closes the account.

EndpointWhat it does
GET /x402/supported
POST /x402/verify
POST /x402/settle
the x402 v2 facilitator API
POST /api/x402/preparecreate the token account of an announced address
GET /api/x402/infonetwork id, fee payer, mints, rent
GET /api/x402/feedevery settlement (address, amount, payer, transaction): public chain facts

Live from this server

Reading /api/x402/info.

Networks: mainnet solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp, devnet solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1, and a local validator as solana:localnet. Another facilitator can be used; addresses are still prepared through nodox, and settlement is up to that facilitator.

04MCP tools for agents

Run nodox-mcp over stdio. It gives an agent these tools:

  • pay_name(name, amount, asset, memo?): pays a nodox name in SOL, USDC or USDT. Checks the registry proof, makes a fresh address, announces it and sends from the agent's wallet. The memo is encrypted for the recipient.
  • create_pay_link(name, amount?, asset?): the name's pay page and a Solana Pay link to one fresh address.
  • list_incoming(sinceMinute?): payments to the agent's own name, found by scanning the log with its view key.
  • quote_relay(asset, amount): what the relay asks to move an amount out of a one-time address.
  • x402_fetch(url, method?, headers?, body?): calls a URL and, on a 402, pays in USDC within the cap and retries.
VariableNeeded forNotes
NODOX_APIall toolsthe nodox server
NODOX_MCP_WALLET_KEYpay_name, x402_fetchthe agent's wallet
NODOX_MCP_PHRASElist_incomingthe agent's own 12 words, used locally only
NODOX_MCP_MAX_USDpay_name, x402_fetchcap per payment in USDC and USDT, default 1
NODOX_MCP_MAX_SOLpay_namecap per payment in SOL, default 0.01

Good practice for agents: confirm with the user before paying anything they did not ask for; read the price in a 402 before paying; never print the phrase or the wallet key; refuse a name that does not verify, and do not retry it against another server.

05Example paid API

examples/paid-api is a Hono server paid through the nodox facilitator to rotating nodox addresses. GET /solana/now costs $0.01 USDC per call.

06Seller income

sellerIncome({ apiBase, keys }) builds the seller's dashboard from public whole-file downloads only: it scans the log with the view key, opens each note, and joins the settlement feed and the balance feed. No request names an address, so the server cannot tell which addresses are the seller's. The nodox app groups these payments and moves them out with the same send.

07Honest limits

  • An address must be prepared before its first payment. The exact transaction cannot create a token account, so the first 402 for a payer in a new hour waits about 1 to 2 seconds.
  • Anonymous payers share one address per hour, and so do payers past the per-hour cap. Their payments are linkable to each other on chain, not to the seller.
  • The payer header is self-declared. It only chooses which of the seller's addresses a buyer pays.
  • Prepaid rent comes back only when the seller moves the money out through the nodox relay. Closing an account elsewhere loses it, and that address is never prepaid again.
  • Prepaying rent and sponsoring settlement fees can be farmed by a seller paying themselves. Each address is prepaid once at most, and daily budgets cap the loss; when a budget runs out, new addresses wait until 00:00 UTC.
  • The seller's server holds the rotation secret. With it and the meta-address, someone can link the seller's x402 addresses (not spend them). The facilitator sees which addresses it prepares and settles.
  • When the nodox server is unreachable or the daily prepaid limits are used up, a new payer's first request fails until it can be prepared. Payers whose address is ready keep working.