# 5 Things Your AI Agent Needs Before You Give It a Wallet

> Source: <https://dev.to/igorvii/5-things-your-ai-agent-needs-before-you-give-it-a-wallet-57im>
> Published: 2026-11-30 15:12:35+00:00

**Recommendation:** Bind an expected price, recipient, asset and network check into the onBeforePaymentCreation hook, and atomically reserve a caller-supplied purchase ID before signing so retries and parallel fan-out never produce a second signature.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

Your AI Agent Can Lose Money 5 Ways. We Sealed All of Them.

In May 2026, an attacker drained roughly $150,000 from a wallet tied to Grok's X account. A gifted NFT unlocked transfer tools — and the instruction arrived hidden in Morse code. The agent translated it, and wired the money. (source)

That made headlines. The boring failures don't.

We run Argus, an independent lab that breaks AI agents that move money — on purpose. Pre-registered probes, black-box targets, every verdict sealed in a public hash-chained registry. So far: 32 signed records against ~20 external subjects, four vendor fixes shipped, $0.00 spent on hostile batteries.

This is the checklist we wish every agent builder had before their first live payment. Five controls. Each exists because we watched real payment code fail without it — and each receipt is public.

Your agent requests a resource. The server answers HTTP 402: pay this much. Does your client compare that number to anything?

The official x402 TypeScript client, in its default configuration, does not. We pointed it at a merchant declaring 10× the canonical price. It signed an authorization for the full inflated amount — three sessions, three signatures, no warning, no error. The configured $1 spend cap looked on: ten cents walks right under it. ([[https://github.com/x402-foundation/x402/issues/3866?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6\]](https://github.com/x402-foundation/x402/issues/3866?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6%5D))

To be precise: the capture is at the signer boundary, settlement mocked, wallet unfunded. But with a compliant facilitator that authorization settles as-is — nothing downstream knows the agreed price.

**A spending cap is a ceiling. It is not a price.**

Today you can enforce an expectation with the onBeforePaymentCreation hook (illustrative — check your SDK version's signature):

``` js
js
client.onBeforePaymentCreation(async (ctx) => {
  const req = ctx.selectedRequirements;
  if (req.amount !== EXPECTED_PRICE_ATOMIC) {
    throw new Error(`quote mismatch: ${EXPECTED_PRICE_ATOMIC} -> ${req.amount}`);
  }
  // bind recipient + asset + network too, not just the number
});
```

A first-class expectedAmount control is ([https://github.com/x402-foundation/x402/pull/3920?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6](https://github.com/x402-foundation/x402/pull/3920?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6)). We tested that fix too — it had races, closed across review cycles. That's a separate field report.

Two identical offers dispatched in parallel. Same resource, same amount, same recipient — one purchase in every human sense. We watched the client sign twice. Both slots returned HTTP 200. Zero rejections. [([https://github.com/x402-foundation/x402/issues/4198?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6)](<https://github.com/x402-foundation/x402/issues/4198?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6)>)]

Price controls don't catch this — both amounts are "correct". This needs its own primitive: a caller-supplied purchase ID, atomically reserved before signing.

```
purchase_id = random()                      # before fan-out
reserve(account, purchase_id, intent_hash)  # atomic, shared
  → first reservation: ALLOW, sign
  → same id + same intent: replay result, never sign again
  → same id + different intent: conflict, reject
```

The design question is open upstream; we've run sealed batteries against candidate implementations. The invariant to demand from any stack: exactly one signature per purchase, even under concurrency.

Receipt: a ten-window idempotency battery against mcp-tool-idempotency — charge replay, retry-after-commit, in-flight takeover, cross-instance races, TTL boundaries. 10/10 PASS on the release, one documented window coordinated with the maintainer before publication.

A cap that reads the window, evaluates, then writes is a suggestion, not a limit.

We pointed a pre-registered battery at a live agent payment gate enforcing $250 per 168 hours. Eight parallel gate checks: seven allowed — roughly $1,400 of simultaneous pending spend against a $250 cap. No settlement occurred (the race sat in the pending-check path), but one burst is all it would take.

The vendor's reply, verbatim: "The race is real on our side, and it is ours to fix." Eight tests before code, then read-evaluate-insert under one advisory lock — live the same day. Re-check: 1 allow, 7 blocks. We then re-ran the full battery under conditions the vendor itself issued, frozen verbatim before the first request: [[https://dev.to/igorvii/pre-registered-re-run-an-x402-payment-hook-battery-under-vendor-issued-conditions-99-13jc?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6](https://dev.to/igorvii/pre-registered-re-run-an-x402-payment-hook-battery-under-vendor-issued-conditions-99-13jc?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6)].

Lesson: check-and-reserve must be one atomic operation. And keep a kill switch you can flip without deploying — the incident will happen at 3 a.m.

200 means "the handler ran". It does not mean "the money moved".

We've sealed the inverse failure too: settlement fails, and the resource is delivered anyway — unpaid, with a receipt. The buyer thinks it paid; the seller thinks it got paid; the chain says otherwise.

Your agent must record per purchase: the payment intent, the authorization it signed, and the settlement evidence (tx hash / facilitator receipt). And treat "no evidence" as a distinct state. Not success. Not failure. Unknown. Unknown has its own handler: reconcile, don't retry blind.

The most expensive class we test: a response gets lost after the payment committed. The agent sees a timeout and retries. The retry charges twice. We've sealed this against real credit/settlement SDKs — lost-response retry double-charging on the default token, no idempotency key, no settlement query.

The recovery rule is one line: on ambiguity, query before you retry.

```
on timeout / lost response:
  status = query_settlement(intent_id)
  if settled:   record evidence, deliver, done
  if not found: retry with the SAME intent id
  if unknown:   escalate to reconciliation — never blind-retry
```

If your payment stack can't answer "did intent X settle?" — that's not a missing feature. That's the finding.

**The checklist (copy it into your README)**

```
[ ] expected price checked pre-signature (cap ≠ price)
[ ] one purchase = one signature (atomic purchase-id reservation)
[ ] race-safe budget + kill switch
[ ] settlement evidence stored; UNKNOWN is a first-class state
[ ] query-before-retry recovery
```

**Test it before your users do**

Every failure above is reproducible from public, version-pinned fixtures. You don't have to trust us:

```
git clone https://github.com/igor-vii/Argus-Agent-Test-Lab
cd Argus-Agent-Test-Lab && node tools/registry/verify-registry.mjs
```

Building an agent that pays? Our console is in open beta — 33 free runs, no card. Every run starts with an honest payment gate; fail it and the run is refunded. There's also a GitHub Action that runs the battery in your CI: [argus-lab.tech].

The field reports behind the receipts: [[https://dev.to/igorvii/your-x402-endpoint-is-one-header-away-from-working-for-free-11d0?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6\].\[https://dev.to/igorvii/pre-registered-re-run-an-x402-payment-hook-battery-under-vendor-issued-conditions-99-13jc?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6](https://dev.to/igorvii/your-x402-endpoint-is-one-header-away-from-working-for-free-11d0?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6%5D.%5Bhttps://dev.to/igorvii/pre-registered-re-run-an-x402-payment-hook-battery-under-vendor-issued-conditions-99-13jc?spm=a2ty_o01.29997173.0.0.6822c921TPCTY6)]

**Building an agent that pays? Tell me your stack in the comments — I'll tell you which of the five is hardest for it.**
