Inspiration
AI agents are starting to pay for things themselves, like data, APIs and groceries. The x402 standard lets a website answer "402 Payment Required, send $0.01 USDC here", and an agent can pay and carry on. To pay, though, the agent needs a wallet, and today that means handing the model a funded key and hoping. A prompt injection, a retry loop or a bad plan can empty it.
Companies solved this for people a long time ago. An employee gets a company card with a limit, a monthly statement and a manager who signs off on big purchases. We wanted the same thing for agents.
What it does
Leash gives an AI agent a USDC wallet on Solana and puts the owner's rules between the agent and the money. Every payment is checked before it is signed.
The owner sets a per-purchase cap ($15 by default), a daily cap ($40) and a per-merchant cap ($20). None of them is a hard ceiling. Past a limit the agent can't sign on its own, and the purchase waits for the owner's approval.
Approvals come to the owner's phone. When a cap blocks something the task needs, our Telegram bot, @LeashSBot, sends the item, the price and the agent's reason with Approve and Deny buttons. Approving pays it once.
Small repeat buys don't have to ask. Past a cap, a purchase of $5 or less from a merchant the agent has already paid goes through on its own, up to $10 a day, and is marked auto-approved. If the owner wants everything stopped, one click in the console or /pause in Telegram freezes all spending until they resume.
Some checks are always on. Every payment is compared with the merchant's wallet on file, its listed price and the owner's task. If something looks off (a different wallet, a higher price at checkout, a purchase the task never asked for), nothing is paid and the owner gets an approval request that says why. The task check reads only the owner's words, so a merchant's reply can't talk the agent into buying something else. The card also has an expiry date.
The Activity list shows every payment and every block with the agent's reason, the rule that fired and a Solana Explorer link for settled payments. The owner can run the agent from the web console or by texting the bot ("buy me two milks"). The demo store sells groceries, a USB-C cable, coffee beans and a $25 gift card, and two data merchants sell live FX rates and the live SOL price.
How we built it
The site, the console and the API routes are built with Next.js 16. The landing page is a scroll story with a Three.js card hanging on a rope, driven by GSAP ScrollTrigger and Lenis.
Payments use x402 (@x402/fetch, @x402/svm, @x402/next). Eight merchants sit behind x402 paywalls in the same app, and the FX and SOL merchants sell real data from open.er-api.com and CoinGecko. The rule engine is a pure function from (rules, spend history, payment) to allow or block. It runs in the x402 client's onBeforePaymentCreation hook, so a blocked payment is never signed. Allowed payments are SPL token transfers of Circle's devnet USDC, built with @solana/kit. We run the x402 facilitator inside the app with its own fee-payer wallet, and it verifies each payment and settles it on Solana.
The Telegram bot uses long polling and shares the approval code with the console, so an approval can't be paid twice from two places.
With an Anthropic key, Claude plans purchases in a tool loop with three tools (list_merchants, pay_and_fetch, request_approval), and a second Claude call does the purpose check. The live demo runs without a key: a scripted planner reads the task, picks merchants and quantities, and calls the same tools. Payments, rule checks and receipts are real either way, and the model never sees the wallet key.
Challenges we ran into
The public x402.org facilitator kept failing to settle, with HTTP 429 errors from its Solana RPC. We moved the facilitator in-process with our own fee payer, and settlement became reliable.
We spent a while deciding where to enforce the rules. After the 402 response and before signing is the only point where we know the real price and payee and the money hasn't moved, and the x402 client's hook sits exactly there.
We also had to decide what an approval can override. An owner approval can pay something that looked off, because the owner has seen why. An auto-approval only lifts the caps, and nothing gets past the pause switch or the expiry date.
Running the bot locally and on the server at the same time made Telegram reject one of the pollers, so only the deployed copy runs the bot now.
Accomplishments that we're proud of
Every payment in the demo is a real USDC transfer settled on Solana devnet, with a receipt link in the console and in Telegram. A blocked payment is refused before a signature exists, so the agent can't argue its way past a cap.
The full loop works from a phone. You text the bot a task, the rules check it, Solana settles it, and an over-limit purchase comes back to you as an Approve button.
What we learned
We learned how x402 works on Solana: the 402 challenge, the signed payment header, and how a facilitator verifies and settles it. We also learned how fee payers work, which is why the agent wallet only needs USDC and a little SOL.
Keeping the model away from the keys made the safety question simpler. We stopped asking whether the model will behave and started asking whether the rules are right.
What's next for Leash
We want to move the rules on-chain with a token-account delegate or a small Solana program, so the owner doesn't have to trust our server either.
We also want real merchants. That means x402 sellers on mainnet, and for ordinary stores, a one-time virtual card issued for each approved purchase so the same rules sit in front of any checkout.
For teams, we plan accounts with a budget per agent and a real database in place of the JSON store. A velocity limit would stop a runaway loop of tiny purchases after a few a minute.
Built With
- anthropic-api
- coingecko-api
- gasp
- next.js
- node.js
- railway
- react
- solana
- solana-kit
- spl-token
- telegram
- three.js
- typescript
- usdc
- x402