/x402-agent-wallet:agent-wallet-policyfrom x402-agent-wallet
Enforces agent spending policies (daily budget, per-request ceiling, merchant/rail caps) before signing x402 payments. Includes in-process library and daemon with HMAC-signed verdicts.
Ships in x402-agent-wallet. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Answers one question for a paying agent: may I spend this? It is both a library
(npm package @nirholas/x402-agent-wallet) and a daemon that returns
HMAC-signed verdicts.
npm install @nirholas/x402-agent-wallet
import { wrapPayerFetch, PolicyViolationError } from "@nirholas/x402-agent-wallet";
const payFetch = wrapPayerFetch(fetch, {
signer: { evm: evmSigner, svm: solanaSigner },
policy: { dailyBudgetUsd: 1, perRequestMaxUsd: 0.05, perRailDailyUsd: { solana: 0.5 } },
});
await payFetch("https://api.example.com/paid"); // throws PolicyViolationError when blocked
The check runs before anything is signed, so a blocked payment never touches a
chain. WalletPolicy fields: dailyBudgetUsd, perRequestMaxUsd,
approvalThresholdUsd, perMerchantDailyUsd, allowedMerchants,
blockedMerchants, allowedNetworks, allowedRails ("evm" or "solana"),
preferRail, perRailDailyUsd. Other exports include NoUsableRailError; an
onVerdict callback receives every verdict for audit logs.
It is a self-hosted Node server (Express, Node 18 or newer). Run it from a clone:
git clone https://github.com/nirholas/x402-agent-wallet && cd x402-agent-wallet
npm install
cp .env.example .env # then adjust; see the comments in the file
npm run dev # tsx src/server.ts, listens on PORT (default 4032)
npm run build then npm start runs the compiled server. npm run client
runs examples/agent-client.ts, a reference paying client. Set PAY_TO_ADDRESS
and SOLANA_PAY_TO_ADDRESS to your own wallets to be paid yourself.
The policy is read from POLICY_FILE (default config/policy.json), the ledger
is stored at LEDGER_FILE, and ADMIN_KEY guards the admin routes (default
dev-admin-key: change it).
| Route | Price | Purpose |
|---|---|---|
POST /policy-check | $0.001 | body merchant, amountUsd, optional resource, network, rail, approvalRef. Returns a signed verdict |
GET /policy | free | the rules and policyDigest |
GET /ledger | free, X-Admin-Key | spend entries and totals |
POST /record-spend | free, X-Admin-Key | body merchant, amountUsd, optional resource, network, verdictId |
POST /verify | free | body { payload, signature }, returns { valid } |
GET /health, GET /.well-known/x402 | free |
A denial is still HTTP 200 with allowed: false and a reason (budget
exhausted, merchant blocked, amount over ceiling). When requiresApproval is
true, resubmit with an approvalRef from a human sign-off.
Paid routes follow the x402 protocol. An unpaid call returns HTTP 402 with an
accepts array listing USDC on Base and USDC on Solana. Sign for one rail,
retry with the base64 payload in the X-PAYMENT header, and the 200 body
carries the result; the settlement receipt is in the X-PAYMENT-RESPONSE
header. Clients: x402-fetch (EVM), @three-ws/x402-payment-modal (browser,
both rails), or any x402 client. The rail networks are chosen by NETWORK
(EVM, base-sepolia by default) and SOLANA_NETWORK in .env; see
.env.example. Settlement moves real USDC on the chosen network: show the user
the recipient, amount and network and get an explicit yes before every paid call.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
agent-wallet, spending-policy, x402, payment-enforcement, budget-control
Other plugins' skills for the same job
npx claudepluginhub nirholas/x402-agent-wallet --plugin x402-agent-wallet