Docs / x402 guard · read 2026-11-26 03:40 UTC

A few lines, and in enforce mode, money moves only on ALLOW.

the same check, run at build: ALLOW run at build, 2026-11-26 03:40 UTC https://studio.mizan.market/api/check/try-me?payee=try-me
js
// x402 guard, enforce mode: money leaves only on a signed ALLOW
const MIZAN = 'https://studio.mizan.market';
async function check(payee, bar) {
  const q = new URLSearchParams({ requirement: bar, payee });
  const r = await fetch(`${MIZAN}/api/check/${encodeURIComponent(payee)}?${q}`);
  return r.json();                       // signed answer: decision, plain, token
}
// payWithYourX402Client: the one function you replace. Call the pay method of the
// x402 client you already use with these requirements, and return its receipt.
async function payWithYourX402Client(requirements) { return { client: 'your x402 client', requirements }; }

export async function payIfEarned(payTo, requirements) {
  const v = await check(payTo, process.env.MIZAN_REQUIRE);
  if (v.decision !== 'ALLOW') return { paid: false, why: v.plain };   // nothing leaves
  const receipt = await payWithYourX402Client(requirements);
  return { paid: true, receipt, answer: v.token };   // the signed answer travels with it
}
python
# x402 guard, enforce mode: money leaves only on a signed ALLOW
import os, json, urllib.parse, urllib.request
MIZAN = "https://studio.mizan.market"

def check(payee: str, bar: str) -> dict:
    q = urllib.parse.urlencode({"requirement": bar, "payee": payee})
    req = urllib.request.Request(f"{MIZAN}/api/check/{urllib.parse.quote(payee)}?{q}", headers={"User-Agent": "my-agent"})
    with urllib.request.urlopen(req) as r:
        return json.load(r)              # signed answer: decision, plain, token

# pay_with_your_x402_client: the one function you replace. Call the pay method of the
# x402 client you already use with these requirements, and return its receipt.
def pay_with_your_x402_client(requirements):
    return {"client": "your x402 client", "requirements": requirements}

def pay_if_earned(pay_to: str, requirements) -> dict:
    v = check(pay_to, os.environ["MIZAN_REQUIRE"])
    if v["decision"] != "ALLOW":
        return {"paid": False, "why": v["plain"]}       # nothing leaves
    return {"paid": True, "receipt": pay_with_your_x402_client(requirements), "answer": v["token"]}
bash
curl -s 'https://studio.mizan.market/api/check/try-me?payee=try-me'

The answer read here is the API's own JSON (decision, plain, token); the Node package returns the same answer with the reason in why.

The guard runs before the payment leaves. A REFUSE carries what would turn it into a yes. Sellers can put the verdict inside the x402 payment requirements: require.

Next: Examples

Public record · every head signed · stamped by outside clocks · the head ↗