Docs

Sell to agents. Buy for agents.

Zowall is a payments platform for x402. Vendors register the endpoints they sell and are verified before they are listed. Buyers get an API key, discover what they can pay for, and pay through a guard that checks every quote first.

Start

Install the SDK

@zowall/sdk and @zowall/x402 are workspace packages in this repository. They are not published to npm, so use them from inside the workspace or copy packages/sdk, packages/x402 and packages/gate-core into your project.

# The packages are workspace packages in this repository. They are not on npm.
git clone <this repository> && cd zowall
pnpm install

# Use them from another package in the workspace:
pnpm --filter <your-package> add @zowall/sdk@workspace:* @zowall/x402@workspace:*

Start

API keys

Sign up as a vendor or a buyer with World ID. One person gets one account and there is no password, and you get a key straight away. It is shown once, and only a hash of it is kept. Create more, or revoke one, under API keys. Send it as Authorization: Bearer <key>, or pass it to the SDK.

export ZOWALL_URL=https://your-zowall-host
export ZOWALL_API_KEY=sk_live_...        # from Dashboard > API keys. Keep it on your server.

Keep keys on your server. A vendor key can register endpoints and create checkout sessions. A buyer key identifies your agents to the platform.

Sell

Register an endpoint

In the dashboard, open Endpoints and fill in the form. Or do the same from code. We call your endpoint once, with no payment, and check that its own 402 names the payee and price you registered. That is also how we know it is yours: another vendor’s URL registered against your account will name theirs.

Register
import { registerEndpoint } from "@zowall/sdk";

const config = { baseUrl: process.env.ZOWALL_URL!, apiKey: process.env.ZOWALL_API_KEY! };

const endpoint = await registerEndpoint(config, {
  name: "Forecast",
  url: "https://api.example.com/forecast",
  payTo: "0.0.1234",
  amount: "10000",                  // atomic units. toAtomic("0.0.0", "0.0001") gives "10000"
  description: "Hourly forecast for any city",
  tags: ["weather", "data"],
});

if (endpoint.status !== "verified") {
  // Saved, but not listed. Each reason is one sentence about what to fix.
  console.log(endpoint.verification?.reasons);
}

It is saved either way. A failing endpoint is not listed, and says why. Fix it, then check again:

import { verifyEndpoint, myEndpoints } from "@zowall/sdk";

const { endpoints } = await myEndpoints(config);      // everything you registered, any state
await verifyEndpoint(config, endpoints[0].id);        // call it again after a fix

Sell

Answer 402

The only thing your endpoint has to do is answer an unpaid request with an x402 quote. Zowall reads v2 (a base64 PAYMENT-REQUIRED header) and the older v1 (a JSON body with maxAmountRequired).

HTTP/1.1 402 Payment Required
PAYMENT-REQUIRED: <base64 of the JSON below>

{
  "x402Version": 2,
  "resource": { "url": "https://api.example.com/forecast" },
  "accepts": [{
    "scheme": "exact",
    "network": "hedera:testnet",
    "amount": "10000",              // atomic units per call
    "asset": "0.0.0",               // HBAR
    "payTo": "0.0.1234",            // the account you register as "paid to"
    "maxTimeoutSeconds": 60,
    "extra": { "feePayer": "<your facilitator's fee payer>" }
  }]
}

Three things must match what you registered: payTo, amount and the resource URL. The network must offer the exact scheme.

Price in HBAR or USDC on Hedera (hedera:testnet, payee 0.0.x), or in USDT on Whitechain (eip155:1874, asset 0xcedfB561…5a7, payee an EVM address). No endpoint of your own yet? The registration form has a button that fills in a working sample for each asset.

Sell

Hosted checkout

To bill a buyer for an invoice, create a checkout session and redirect them to it. The page shows what is being paid and the checks the gate has already run, and takes the payment. You never touch the buyer’s funds.

import { createCheckoutSession, signInvoice } from "@zowall/sdk";

// You sign an invoice as you always did...
const signature = await signInvoice(invoice, { privateKey: vendorKey, chainId: 1874, gateAddress });

// ...and ask for a checkout instead of handing the buyer a signature.
const { url } = await createCheckoutSession(config, {
  invoice,
  signature,
  description: "2 cables",
  successUrl: "https://shop.example/thanks",   // the session id is appended
  cancelUrl: "https://shop.example/cart",
});

redirect(url);                                   // send the buyer here

A complete merchant server is in apps/merchant-demo: a shop page, a Pay button that creates the session, and the redirect. It is about 130 lines.

Buy

Discover endpoints

Browse the registry, or query it from your agent. Discovery is public and lists only endpoints that are verified.

import { discoverEndpoints } from "@zowall/sdk";

// Public. No key needed, and nothing is sent that identifies you.
const { total, endpoints } = await discoverEndpoints(
  { baseUrl: process.env.ZOWALL_URL! },
  { q: "forecast", tag: "weather", network: "hedera:testnet", limit: 20 },
);

for (const e of endpoints) console.log(e.name, e.url, e.amount, e.asset, e.payTo);

Buy

Verify the people on an order

An order has a creator, a receiver and an approver, and the gate refuses to let one person hold two of those roles. Each person verifies once with World ID under People. Their verified identity is what the gate compares, so the SDK never handles World proofs: you pass the attestation, the contract checks it.

Buy

Pay with x402

Wrap your agent’s fetch. Each 402 is matched against a mandate you set, so an agent can only pay what a person agreed it could, to the account that was agreed. Your existing x402 client does the signing.

import { createGuard, withZowall } from "@zowall/x402";

const guarded = withZowall({
  // Checks every 402 against a mandate before anything is signed.
  guard: createGuard({ keccak256, findMandate, roles }),

  // Your x402 client still does the paying. It is only called for a quote that passed.
  signPayment: async (quote) => ({ payload: await buildPayload(quote) }),
});

// Anything that is not a 402 passes straight through.
const response = await guarded(endpoint.url);

// A refusal is a 402 carrying the reason codes. Nothing was signed.
if (response.status === 402) {
  const { zowall } = await response.json();
  console.log(zowall.outcome, zowall.codes);
}

Buy

Pay an invoice

For invoices from a vendor, use the gate. Preview first, then pay. A refusal comes back as a result, not an exception, and every failing reason is listed.

import { createGate } from "@zowall/sdk";

const gate = createGate({ gateAddress, publicClient, walletClient });

const preview = await gate.preview(invoice, signature);   // changes nothing, costs no gas
const result = await gate.pay(invoice, signature);        // never throws on a bad document

if (result.outcome === "PAID")     { /* USDT moved to the payee, in this transaction */ }
if (result.outcome === "HELD")     { /* parked for a person to approve */ }
if (result.outcome === "REJECTED") { /* nothing moved. result.codes lists every reason */ }
OutcomeWhat to do
PAIDRecord txHash and carry on.
HELDDo not resubmit. A person decides it; funds stay reserved.
REJECTEDStop. Read result.codes. The vendor re-signs a corrected invoice.

Reference

Registry API

CallKeyDoes
GET /api/registry/endpointsnoneList verified, public endpoints. Filters: q, tag, network, asset, limit, offset.
GET /api/registry/endpoints?mine=1vendorList everything you registered, in any state.
GET /api/registry/endpoints/:idnoneOne endpoint. Private ones are visible only to their vendor.
POST /api/registry/endpointsvendorRegister and verify an endpoint.
PATCH /api/registry/endpoints/:idvendorChange a name, description, tags, visibility or price.
POST /api/registry/endpoints/:id/verifyvendorCall the endpoint again and record what it said.
DELETE /api/registry/endpoints/:idvendorRemove it.
POST /api/checkout/sessionsvendorCreate a hosted checkout from a signed invoice.

Errors are JSON, { "error": "…" }, with the status that fits: 400 for a bad request, 401 for a missing or revoked key, 403 for the wrong kind of account, 404 for something that is not there or not yours, 409 for an endpoint already registered.

Reference

Statuses

StatusMeaning
verifiedIts own 402 matched the registration. Listed, if public.
failingSaved, not listed. verification.reasons says what to fix.
pendingRegistered but not yet checked.

Public endpoints are fetched by the platform to verify them. It will not call a private address, follow a redirect, or wait more than eight seconds, and it only ever sends a plain GET.

Reference

Reason codes

When a payment is refused, every failing code comes back, not just the first. Hard codes refuse; soft codes hold the payment for a person.

CodeSeverityMeaning
NO_POrefuseThere is no open purchase order for this invoice.
BAD_SIGNATURErefuseThis invoice was not signed by the vendor key on the purchase order.
PAYEE_MISMATCHrefuseThe payment address does not match the one on the purchase order.
PO_EXPIREDrefuseThe purchase order expired before this invoice arrived.
PO_CLOSEDrefuseThis purchase order is fully invoiced and closed.
DUPLICATE_INVOICErefuseThis invoice has already been submitted.
BUDGET_EXCEEDEDrefuseThis invoice would take the total past the purchase order value.
SOD_VIOLATIONrefuseThe same person holds two roles on this purchase order.
NO_RECEIPTholdNothing has been recorded as received yet.
QTY_OVER_RECEIVEDholdThe invoiced quantity is more than was received.
PRICE_OVER_TOLERANCEholdThe unit price is above the agreed price and tolerance.

Reference

Environment

VariableUsed for
ZOWALL_URLWhere the platform is served. The SDK's baseUrl.
ZOWALL_API_KEYYour key. Required to register endpoints and create checkouts.
GATE_ADDRESSThe deployed gate, for paying invoices with the SDK.
PRIVATE_KEYThe agent's wallet, which sends transactions and pays gas.
VENDOR_PRIVATE_KEYA vendor's invoice-signing key. Only the vendor holds it.

This deployment’s gate is 0x8ec88c90d675594ab969ed1180f8b887dfac1c71 on chain 1874.