onchain-agent-wallets
onchain-agent-wallets
给 AI 代理一个真实的 Solana 钱包,但不用交出你的钱。
一个 MCP 服务器,给任何代理发放消费额度,而不是私钥。资金留在你拥有的账户里。代理获得的是 SPL Token 程序在链上限制的委托额度,加上你控制的护栏规则,以及从该额度中支付 x402 API 的能力。你可以用一条指令撤销,不用问代理就能把钱拿回来。
这里没有任何模拟:真实的 SPL Token 委托、真实的 Solana、真实的 x402 结算。
它解决的问题
如今每个"代理钱包"的做法都一样:你生成一个密钥对,交给代理,然后代理就拥有了里面的一切。没有上限、没有白名单、没有过期时间,也没有办法在竞速中抢在代理之前把资金转走。人们只好往里面放很少的钱,结果代理什么有用的事都做不了。
额度授权是更古老、更好的答案。钱从不转移到代理手里。代理只获得花其中一小部分的权限,而链本身强制执行这个限额。
Related MCP server: Slug Wallet
工作原理
YOU (Phantom, Solflare, Ledger)
│ owns the vault, holds the money, can revoke or withdraw at any time
▼
┌──────────────────────────────────────────┐
│ vault token account │ derived from your address:
│ owner = you │ createWithSeed(you, "oaw1:<agent>")
│ balance = 500 USDC │
│ delegate = the agent ← capped at 100 │ SPL Token enforces this number
└──────────────────────────────────────────┘
▲
│ may spend up to the cap, and not one unit more
AGENT (its own keypair, holds only fee SOL)两层独立的保护机制守护着你:
链上。 SPL Token 程序会检查每一笔代理签名的转账,对照
delegated_amount,并在每次消费时递减。我们的代码无法提高这个额度。一次revoke就能把它归零。这是 SPL Token 程序自带的功能,不是需要信任的新合约。本地。 在服务器签署任何内容之前,它会应用你的规则:单笔交易上限、24 小时滚动上限、收款人白名单、x402 主机白名单、过期时间、暂停开关,以及超过阈值必须人工确认。
代理自己的密钥对里只有一点点 SOL 用来付手续费。就算泄露了,影响范围也仅限于剩余额度,而 revoke_agent_wallet 一笔交易就能关闭一切。
安装
npm install -g @three-ws/onchain-agent-wallets
# or run it ad hoc
npx -y @three-ws/onchain-agent-wallets配置
Claude Code:
claude mcp add onchain-agent-wallets -- npx -y @three-ws/onchain-agent-wallets或任何 MCP 客户端(mcp.json):
{
"mcpServers": {
"onchain-agent-wallets": {
"command": "npx",
"args": ["-y", "@three-ws/onchain-agent-wallets"],
"env": {
"OAW_NETWORK": "mainnet"
}
}
}
}无需密钥即可启动。所有者操作会以未签名交易的形式返回,由你的钱包签署,再由 send_signed_transaction 广播。如果你希望服务器代为签署,可以设置 OWNER_SECRET_KEY。
变量 | 默认值 | 作用 |
| 未设置 | 所有者密钥,base58 或 JSON 字节数组。可选:不设置时由你在 Phantom 中签署。 |
|
|
|
| 公共端点 | 你自己的 RPC。公共端点限流很严。必须是 https。 |
|
| 代理密钥对、护栏规则和消费账本的存放位置(0700 目录中的 0600 权限文件)。 |
|
| 所有涉及资金变动的工具,没有 |
快速开始
给研究代理 100 USDC 的消费额度,单笔上限 5,每日上限 20,只允许访问一个 API:
create_agent_wallet
id: "researcher"
allowance: "100"
per_tx: "5"
daily: "20"
allow_hosts: ["api.example.com"]
confirm: true
fund_agent_wallet id: "researcher" amount: "500" sol: "0.02" confirm: true代理现在可以自己花钱了:
pay_x402 id: "researcher" url: "https://api.example.com/premium" confirm: true
agent_pay id: "researcher" to: "<address>" amount: "2.50" confirm: true而你始终掌控一切:
agent_wallet_status id: "researcher" # live balances, remaining allowance, warnings
spend_log id: "researcher" # every spend AND every refusal, with reasons
set_guardrails id: "researcher" paused: true # instant, free, no transaction
revoke_agent_wallet id: "researcher" withdraw: true confirm: true # on-chain kill switch被拒绝时,它会明确告诉你触发了哪条规则:
{
"ok": false,
"error": "over_daily",
"message": "20.5 would exceed the 20 daily cap (18 already spent)",
"checks": [
{ "check": "per_tx", "ok": true, "detail": "2.5 is within the 5 per-transaction cap" },
{ "check": "daily", "ok": false, "detail": "20.5 would exceed the 20 daily cap (18 already spent)" }
]
}工具
托管(你来签署)
工具 | 作用 |
| 生成代理密钥对,创建金库,设置委托额度,配置护栏规则。一次调用完成。 |
| 向金库转入代币,并向代理转入 SOL 作为手续费。 |
| 提高、降低或补充链上委托额度。取代之前的额度。 |
| 从金库取回资金。即使没有活跃的委托也能操作。 |
| 紧急开关。将委托额度归零,并可选地在同一笔交易中把余额转回。 |
| 广播你的钱包签署的交易。 |
护栏规则
工具 | 作用 |
| per_tx、daily、allow_recipients、allow_hosts、expires_at、confirm_over、paused。即时生效,免费。 |
消费(代理来签署)
工具 | 作用 |
| 向收款人发送代币,受限额约束。 |
| 调用 x402 API,从额度中支付。 |
查看
工具 | 作用 |
| 实时链上状态、护栏规则、24 小时和 7 天消费汇总、警告信息。 |
| 所有代理及其余额。 |
| 审计日志,包括被拒绝的记录。 |
部署
工具 | 作用 |
| 为代理铸造 Metaplex Agent Registry 身份,链上属性中记录其支付地址。 |
| 导出 mcp.json 和身份凭证,让代理在其他地方运行。 |
护栏规则
规则 | 作用 | 执行方 |
allowance | 代理在获得新授权前总共可花费的额度 | SPL Token 程序,链上 |
vault | 代理不能花金库里没有的钱 | SPL Token 程序,链上 |
| 单笔交易最高金额 | 本服务器 |
| 24 小时滚动窗口内的最高消费 | 本服务器 |
| 只有这些地址可以收款。为空则不受限制。 | 本服务器 |
| 只有这些主机可以通过 x402 收款。子域名继承。为空则不受限制。 | 本服务器 |
| 此时间戳之后拒绝一切消费 | 本服务器 |
| 超过此金额的消费需要显式的 | 本服务器 |
| 立即拒绝一切,免费 | 本服务器 |
区别在于出事的时候:如果这台机器被攻破了,本地规则可以被绕过,但链上额度依然无法突破。所以额度应该设为刚好够代理干活的最小数字,需要时再补充,而不是把全部余额都放进去。
x402
pay_x402 会先探测端点是否收费,所以在任何资金移动之前就能知道价格,护栏规则也能看到真实数字。然后它从金库中精确取出所需金额,完成支付,代理账户里不留余额。
以下情况它会拒绝支付:
非 Solana 链(
no_solana_option)错误的网络环境,比如用 devnet 钱包支付 mainnet 价格(
wrong_cluster)代币类型与额度不匹配(
asset_mismatch)超过
max_price,这是独立于常设护栏的每次调用上限(over_max_price)
如果端点不收费,内容直接返回,什么都不花。
代理做不到的事
无论怎么提示,都不能超过额度消费。决定权在 Token 程序,不在模型。
不能转移金库、关闭金库或更换所有者。它不是所有者。
不能阻止你提款,也不能阻止撤销操作。
不能提高自己的额度。只有所有者签署的
approve才能做到。不能碰你钱包里的任何其他东西。金库是一个独立账户,只存放你放进去的东西。
已在 test/token-delegation.test.mjs 中验证:该测试在进程中运行真实的 SPL Token 程序,断言在剩余额度为 60 时尝试消费 61 会在链上失败,而金库中保留着 460。
在 devnet 上免费演练
OAW_NETWORK=devnet npx -y @three-ws/onchain-agent-wallets状态按网络分别保存,所以 devnet 演练绝不会影响你的 mainnet 代理。
作为库使用
托管模型就是纯粹的 @solana/web3.js 和 @solana/spl-token,不依赖 MCP 也能用:
import { createVaultInstructions, readVault, spendableUnits } from '@three-ws/onchain-agent-wallets/lib/vault';
const { vault, instructions } = await createVaultInstructions({
connection,
owner: ownerPubkey,
agentId: 'researcher',
mint: usdcMint,
delegate: agentPubkey,
allowance: 100_000_000n, // 100 USDC
decimals: 6,
});
// sign `instructions` with the owner, then:
const state = await readVault({ connection, vault });
console.log(spendableUnits(state)); // what the agent may spend right now@three-ws/onchain-agent-wallets/lib/policy 单独导出了护栏引擎,如果你想在不同运行时中使用相同的规则。
测试
npm test运行护栏单元测试、x402 选择测试,以及针对真实 SPL Token 程序的委托集成测试。
相关项目
@three-ws/metaplex-agent-mcp将代理身份铸造到 Metaplex Agent Registry 中。deploy_agent_onchain将其作为库使用,它的prepare_agent_mint是浏览器钱包铸造路径。three.ws 是这些代理获得形象、头像和家园的地方。
许可证
见 LICENSE。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAI-native Solana wallet CLI with scoped MCP server, enabling AI agents to manage wallets with granular permissions, spend limits, and tamper-evident audit logging.5
- AlicenseNot gradedqualityCmaintenanceMCP server that gives terminal AI agents a guarded USDC wallet with firewall, automatic 402 payment handling, and budget limits.7MIT
- AlicenseAqualityCmaintenanceAn MCP server providing policy-gated Solana access for AI agents, with read-only operations and guarded transfers that require policy checks and simulation, returning unsigned transactions.7MIT
- AlicenseBqualityCmaintenanceAn MCP server that enables AI agents to interact with the Solana blockchain through 20 tools for wallet management, SPL token operations, blockchain exploration, and DeFi integration via Jupiter.21MIT
Related MCP Connectors
Native Solana staking for AI agents. 26 MCP tools, one-shot signing, webhooks.
Solana token risk-scoring MCP server for AI trading agents with insider wallet cluster detection.
MCP server connecting AI agents to non-custodial staking data across 130+ networks.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/nirholas/onchain-agent-wallets'
If you have feedback or need assistance with the MCP directory API, please join our Discord server