SpendPreflightdocs
Start / developer guide

x402 preflight examples: allow, hold and block

Follow one hypothetical quote through three spending decisions, then handle an unavailable screening response.

Operator-maintained documentation
Live features and staging previews are distinguished. Index coverage is not yet available.

The common request

These are hypothetical examples, not live merchant observations. The example.com URL and repeated-digit recipient are placeholders, not a destination to pay. The quote uses native USDC on Base, which has six decimals: 10000 atomic units is 0.01 USDC. This HTTP request reviews a merchant quote; the merchant amount is separate from the 0.02 USDC remote preflight fee.

Copy snippet
{
  "challenge": {
    "x402Version": 2,
    "resource": {
      "url": "https://api.example.com/data"
    },
    "accepts": [
      {
        "scheme": "exact",
        "network": "eip155:8453",
        "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
        "payTo": "0x1111111111111111111111111111111111111111",
        "amount": "10000",
        "maxTimeoutSeconds": 60
      }
    ]
  },
  "resource_url": "https://api.example.com/data",
  "resource_method": "GET",
  "rules": {
    "max_per_payment_usd": 0.05,
    "hold_above_usd": 0.02,
    "daily_cap_usd": 0.1,
    "allowed_networks": [
      "eip155:8453"
    ],
    "usdc_only": true,
    "strict_allowlist": true,
    "domain_allowlist": [
      "api.example.com"
    ],
    "payto_allowlist": [
      "0x1111111111111111111111111111111111111111"
    ]
  },
  "context": {
    "spent_today_usd": 0.02
  }
}

Allow: 0.01 USDC within the configured rules

With amount "10000", the quote is below the 0.02 human-review threshold and the 0.05 maximum. Under the local test fixture, the domain/recipient allowlists match, mock sanctions screening has no match, and mocked domain evidence passes. The result is allow with reason "allow: all rules passed". In a real response, inspect the exact chosen option and evidence. Allow applies to the evaluated terms and rules; it does not authorize the wallet or certify the merchant.

Hold: 0.03 USDC needs human review

Change only accepts[0].amount to "30000". It remains below the 0.05 maximum but exceeds hold_above_usd: 0.02. The fixture returns hold with reason "hold: amount $0.03 above hold threshold $0.02". Show the amount and reasons to the authorized reviewer and wait. Never turn hold into allow by retrying or increasing limits automatically.

Block: 0.06 USDC exceeds the cap

Change only accepts[0].amount to "60000". It exceeds max_per_payment_usd: 0.05. The fixture returns block with reason "block: amount $0.06 exceeds max $0.05". Stop this payment. A new spending policy needs its own authority; this example does not grant an exception.

Run the walkthrough without a wallet

Use Node.js 20 or newer. Download preflight-decisions.mjs below and the existing http.mjs helper into the same directory, then run node preflight-decisions.mjs. It injects illustrative response fixtures and makes zero HTTP requests. Expected decisions, in order: allow, hold, block, hold. The final hold simulates an exhausted trial returning HTTP 402; there is no automatic paid fallback. The request fixtures are tested against the local preflight engine with mock sanctions, domain and DNS sources, not a live merchant or current screening result.

preflight-decisions.mjs
// Offline walkthrough: illustrative responses, no HTTP request or payment.
// Save this file and http.mjs in one directory; run with Node.js 20+.
import { pathToFileURL } from "node:url";
import { preflightTrial } from "./http.mjs";

const quote = (amount) => ({
  x402Version: 2,
  resource: { url: "https://api.example.com/data" },
  accepts: [{
    scheme: "exact", network: "eip155:8453",
    asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    payTo: "0x1111111111111111111111111111111111111111",
    amount, maxTimeoutSeconds: 60,
  }],
});
const rules = {
  max_per_payment_usd: 0.05, hold_above_usd: 0.02, daily_cap_usd: 0.10,
  allowed_networks: ["eip155:8453"], usdc_only: true,
  strict_allowlist: true, domain_allowlist: ["api.example.com"],
  payto_allowlist: ["0x1111111111111111111111111111111111111111"],
};
export const scenarios = [
  { name: "Within the configured rules", amount: "10000", decision: "allow", reason: "allow: all rules passed" },
  { name: "Above the human review threshold", amount: "30000", decision: "hold", reason: "hold: amount $0.03 above hold threshold $0.02" },
  { name: "Above the maximum payment", amount: "60000", decision: "block", reason: "block: amount $0.06 exceeds max $0.05" },
].map((s) => ({ ...s, input: {
  challenge: quote(s.amount), resource_url: "https://api.example.com/data",
  resource_method: "GET", rules: { ...rules }, context: { spent_today_usd: 0.02 },
} }));

export async function runOfflineWalkthrough() {
  const results = [];
  for (const s of scenarios) {
    // This injected response is a fixture, not a live or signed service result.
    const result = await preflightTrial(s.input, async () => Response.json({
      decision: s.decision, reasons: [s.reason],
    }));
    results.push({ example: s.name, decision: result.decision });
  }
  const unavailable = await preflightTrial(scenarios[0].input, async () => new Response(null, { status: 402 }));
  results.push({ example: "Screening trial unavailable; no paid fallback", decision: unavailable.decision });
  return results;
}

if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
  console.log(JSON.stringify(await runOfflineWalkthrough(), null, 2));
}
Download tested source

Use a real response deliberately

The HTTP helper accepts an explicitly eligible trial; three trials per IP per UTC day are shared with MCP. If you choose to call it without the injected fixture response, it makes a real screening request. Unavailable, malformed or exhausted-trial responses hold. Paid mode needs a separately approved x402 screening payment. Keep your own authoritative spend ledger, include the selected resource and exact terms, and enforce the returned decision before signing. This walkthrough deliberately does not forge or cryptographically verify a signed receipt.

Missing evidence is still unknown

The examples isolate spending thresholds. They do not invent endpoint history or test paid delivery. Other rules can produce a different live result. If the merchant changes resource, recipient, amount, asset or network, evaluate the changed terms; do not reuse an earlier allow. Follow the response reasons and retain the distinction between a screening decision, wallet authority and a completed payment.