Inspiration
As companies begin giving AI agents their own wallets to purchase data, APIs, and computing resources, we started thinking about a question that doesn't get enough attention: Who is actually auditing these agents?
Think about how a company handles employee spending. Giving someone a company credit card doesn't mean they can spend whatever they want. There are spending limits, approved vendors, approval requirements, and someone reviewing transactions afterward to make sure everything was legitimate.
We realized that most agent payment systems focus heavily on controlling how much an agent can spend, but not necessarily what happens after the payment.
A spending limit won't catch a payment made with a stolen key. And a successful transaction doesn't necessarily mean the seller delivered what was promised.
That's why we built Agent Auditor: an internal control and auditing layer designed to bring accountability and transparency to autonomous AI spending, with Solana serving as an independent source of truth.
What it does
Agent Auditor separates the responsibilities of an AI agent, a payment gateway, and an independent auditor.
Agent-controlled purchasing: Claude Haiku submits purchase orders through a single tool. It never has direct access to the wallet or its private key. The gateway handles all payments.
Preventive controls: Before any payment is made, the gateway checks a set of hardcoded rules stored in a JSON configuration file. These include approved sellers, a $1 per-purchase limit, a $5 daily spending limit, and human approval for purchases above $0.50. If a transaction doesn't meet the requirements, it gets denied.
Independent monitoring: QuickNode Streams monitors every USDC payment leaving the wallet, including transactions that bypass the gateway entirely. Each payment is matched to its purchase order using an on-chain transaction memo.
Accounting and exceptions: Valid purchases are automatically recorded as double-entry journal entries. Suspicious or unmatched transactions are flagged for human review, where an operator can approve the transaction or block the seller.
We built four live demo scenarios on Solana devnet:
A normal purchase where everything works as expected.
A dishonest seller that accepts payment but never delivers the product.
A prompt-injected purchase that attempts to trick the AI agent.
A payment made using a stolen wallet key that completely bypasses the gateway.
How we built it
We built the entire application using Next.js and TypeScript. The same application hosts the payment gateway, three demo sellers, the QuickNode Streams webhook, and the auditing dashboard.
For the backend, we use Supabase and PostgreSQL to manage six tables: sellers, orders, payments, deliveries, journal entries, and exceptions. Supabase Realtime keeps the dashboard updated as events happen. The application is deployed on Vercel.
Payments are handled through real x402 seller endpoints. When the gateway requests data, the seller responds with a 402 Payment Required response containing a payment quote. The gateway evaluates the request, makes the payment using devnet USDC, and retries the request. PayAI handles payment verification and settlement.
One important part of our implementation is that spending rules are enforced inside x402's onBeforePaymentCreation hook. This means a transaction is checked before it is even constructed, so a rejected purchase never moves money.
For independent monitoring, every payment includes its order_id as an SPL Memo. QuickNode Streams monitors Solana devnet's Block dataset, filtered to our wallet, and sends detected transactions to our webhook.
The webhook then:
Verifies the QuickNode HMAC-SHA256 signature.
Filters for successful USDC transfers leaving our wallet.
Matches the transaction memo to an existing purchase order.
Creates a critical exception if a payment cannot be matched.
We also made sure that financial calculations never rely on floating-point numbers. Every USDC amount is stored as an integer in its smallest denomination, called base units.
For example:
1 USDC = 1,000,000 base units
A purchase is allowed under the daily spending rule only when the total remains within the $5 limit.
Testing was another major part of the project. We wrote 461 Vitest tests across 27 files. The gateway uses injected dependencies, which allowed us to test different scenarios without actually interacting with the blockchain.
We tested payment denials, race conditions, duplicate webhooks, and transactions that were signed but never confirmed. We also configured pre-commit hooks and CI to run typechecking, linting, tests, and builds whenever changes are made.
Challenges we ran into
One of our biggest challenges was figuring out how transaction memos actually work with x402 on Solana.
We initially designed our entire payment-matching system around the idea that the buyer could choose the transaction memo. However, we discovered that in x402 v2, the seller actually sets the memo in its payment quote.
This meant our original design wouldn't work as expected. We ran a dedicated devnet test to verify the behavior before building further. Our solution was to create a seller contract requiring sellers to echo the gateway's X-Order-Id as the memo. We also added a guard that refuses to sign any quote where the memo doesn't match the order ID.
We also had trouble with payment settlement. Our initial facilitator, x402.org, failed all 13 of our devnet settlement attempts. After testing PayAI, we saw successful settlements and switched to it.
Another challenge was understanding how Solana handles token accounts. USDC doesn't move directly between wallet addresses. Instead, it moves between token accounts, so we had to resolve each account's actual owner using the transaction's token balance information.
We also had to account for the fact that payments and delivery confirmations don't necessarily arrive in the same order. QuickNode Streams might report a payment before the gateway confirms delivery, or the other way around. We implemented a system that waits until both events arrive before recording the purchase. A conditional database update ensures that the same purchase can never be recorded twice.
One particularly important lesson came from handling uncertain payment confirmations. If a payment is signed but we can't confirm whether it settled, automatically retrying could result in the agent paying twice. Instead, we leave the order open so that if the original payment eventually appears on-chain, it can still be matched correctly.
Finally, we ran into some difficulties demonstrating prompt injection. Recent Claude models often resist the injected instructions we used in our demo. Rather than depending on the model actually getting fooled, we made the scenario submit the purchase order that a compromised agent would have created. This helped demonstrate our main point: even if the AI makes a bad decision, the gateway should still enforce the rules.
Accomplishments that we're proud of
We're especially proud that all four scenarios work live on Solana devnet.
One of the most important demonstrations is the stolen-key scenario. We intentionally bypass the gateway and make a payment directly using the wallet key. Despite bypassing every preventive control, QuickNode detects the transaction and our system flags it approximately one second after its block.
We also built the system around a clear separation of responsibilities:
The AI agent can request purchases.
The gateway can authorize and execute payments.
The independent auditor monitors what actually happens on-chain.
Most importantly, the auditor doesn't simply trust the payment gateway's own logs. It verifies transactions against the blockchain independently.
What we learned
This project taught us that autonomous payments need more than spending limits.
Preventive controls and detective controls solve different problems. A gateway can prevent unauthorized payments that pass through it, but it cannot detect transactions made by someone who has bypassed it. Blockchain monitoring can detect those transactions, but it can't prevent them from happening in the first place.
We also learned that important financial decisions shouldn't be left to an AI model. Prompts can guide an agent, but actual spending restrictions need to be enforced through code that the agent cannot override.
Finally, we learned the importance of testing our riskiest assumptions early. Our entire transaction-matching design depended on how Solana handled payment memos in x402. Testing that behavior first saved us from building the wrong system.
What's next for Agent-Auditor
Agent Auditor is a working prototype, but there are several things we'd like to improve.
Our next priorities include:
Automatically freezing the wallet and rotating its key when a stolen-key payment is detected.
Implementing automated daily reconciliation.
Reserving spending capacity as soon as an order is placed to prevent concurrent orders from exceeding the daily limit.
Building configurable human approval workflows.
Supporting multiple AI agents with separate spending policies.
Introducing seller trust scores based on delivery history and transaction behavior.
Improving production-grade wallet security and key custody.
Our long-term goal is to make Agent Auditor a reliable financial control layer for companies deploying autonomous AI agents, so businesses can give their agents the ability to spend money without having to blindly trust them.
Built With
- anthropic
- claude
- next.js
- node.js
- payai
- postgresql
- quicknode
- quicknode-streams
- react
- solana
- solana-kit
- supabase
- typescript
- usdc
- vercel
- vitest
- x402