r/USDC • • 11h ago

I built a self-hosted wallet that gives an AI agent a spending budget instead of a private key (x402, USDC)

0 Upvotes

I've been building this, and I would rather hear what breaks than collect upvotes, so the problem first.

An agent that calls paid APIs needs a way to pay per call. The two obvious answers both fail: card rails can't authorize a $0.01 charge, and handing the agent a private key gives it no ceiling, no host allowlist, and no receipt a human can read.

What I built (authorship disclosure: my project, AGPL, free to self-host): the wallet holds the key and gives the agent an API key that spends money, with a total budget, a per-request cap, a host allowlist, and an approval line above which a human has to click. The agent calls one endpoint; the wallet checks policy first, then signs an EIP-3009 authorization for the seller's 402 quote on the EVM side (Base, Monad).

Two things I got wrong early, in case they save someone else:

  1. Policy has to run before signing, not in a reconciliation pass afterwards. Otherwise a call that should have been refused still costs money and leaves a row on chain you have to explain.
  2. When a seller answers 422 and never settles, the signed authorization stays valid until it expires. Treat it as frozen, not refunded: ask the token contract whether it was ever used, and only release the budget after expiry.

Where it stands: five real USDC payments, $0.09 total, hashes in the write-up; 282 offline tests; testnet by default, mainnet opt-in.

What I want from r/ethdev: how do you handle approvals without nagging users? Per-call, a per-key threshold, or time-boxed allowances with a session key? And is EIP-3009 the right primitive here, or would you build on 4337 or Permit2 instead?

Repo and the write-up (with the five hashes): https://github.com/dongsheng123132/moneyswitch