Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

A Paying Client That Cannot Overspend: Mandatory Caps for x402 Buyer Agents

说明与用途

没有支出限制的客户端可能导致钱包被耗尽;@agentbadge/circle-payments 库强制执行必需的支付上限和会话预算,在签名前拒绝请求以防止超支。

问题

A paying client without spending limits can cause runaway loops that drain a wallet, leading to unintended charges.

结果

The mandatory caps and session budget enforcement prevented three failed payment attempts from draining the wallet, with zero on-chain settlement on rejected requests.

工作流

  • Create a paying client with caps and signer
  • Call an API endpoint that returns a 402 with payment requirements
  • Client validates accepts list and checks per-call cap, network, and session budget
  • If any check fails, client returns a refusal without signing
  • If all checks pass, client signs the payment payload and retries the request
  • On successful settlement, spend is recorded and persisted via onSpend hook

证据

Three times, three different ways: once for the per-call cap, once for the network allowlist, once for the session budget.

来源

createPayingClient throws a TypeError the moment you omit PaymentCaps, before a single request leaves the process.

来源

refused field=amount value="300000": amount 300000 exceeds per-call cap 10000 (atomic units) refused field=network value="eip155:84532": network "eip155:84532" not in allowedNetworks refused: Session budget exhausted: spent 0 + requested 300000 > budget 10000 (atomic units)

来源

  • 记录日期: 2026-10-15T22:41:16.532Z