用户授权执行链上交易,基于 MetaMask ERC‑7715,无需私钥,全防护。
钱包Pilot- 7715. 给您的AI代理加密超能力, 并使用 MetaMask ERC- 7715权限.是一项面向实际任务的技能,主要用于Overview.;WalletPilot 允许AI代理使用 MetaMask的 ERC- 7715 perm 执行链上交易。
实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;
涉及批量任务时,还应保存进度,避免中断后重复操作。该技能适合用于一次性任务,也可以接入自动化工作流,与其他技能或上层代理配合完成更完整的业务链路;在组合使用时,应明确每一步的输入输出关系,并避免不同步骤之间出现参数冲突。
借助 MetaMask 的 ERC-7715 权限标准,为您的 AI agent 赋予加密货币操作能力。
WalletPilot 使 AI agent 能够基于 MetaMask 官方 ERC-7715 权限标准执行链上交易。用户只需一次性授予受限权限(例如支出限额、链限制),此后 agent 即可在该权限范围内自由执行操作。
核心特性:
npm install @walletpilot/sdk向用户请求钱包权限。
import { WalletPilot, PermissionBuilder } from '@walletpilot/sdk';
const pilot = new WalletPilot({ apiKey: 'wp_...' });
const permission = new PermissionBuilder()
.spend('USDC', '100', 'day') // 每日最多花费 100 USDC
.spend('ETH', '0.1', 'day') // 每日最多花费 0.1 ETH
.chains([1, 137, 42161]) // Ethereum、Polygon、Arbitrum
.expiry('30d') // 权限有效期为 30 天
.build();
const { deepLink } = await pilot.requestPermission(permission);
console.log('用户应打开:', deepLink);
使用已授予的权限执行交易。
const result = await pilot.execute({
to: '0x1234...', // 目标合约地址
data: '0xabcd...', // calldata(例如:兑换操作)
value: '0', // ETH 数值(可选)
chainId: 1, // 链 ID
});
console.log('交易哈希:', result.hash);
查询代币余额(使用标准 RPC 接口,无需额外权限)。
import { createPublicClient, http } from 'viem';
import { mainnet } from 'viem/chains';
const client = createPublicClient({
chain: mainnet,
transport: http(),
});
const balance = await client.getBalance({ address: '0x...' });
通过 DEX 聚合器执行代币兑换。
// 从 1inch、0x 等获取兑换报价
const quote = await fetch('https://api.1inch.io/v5.0/1/swap?...');
const { tx } = await quote.json();
// 通过 WalletPilot 执行
await pilot.execute({
to: tx.to,
data: tx.data,
value: tx.value,
chainId: 1,
});
向指定地址发送代币。
import { encodeFunctionData, erc20Abi } from 'viem';
// 编码 ERC20 transfer 调用
const data = encodeFunctionData({
abi: erc20Abi,
functionName: 'transfer',
args: ['0xRecipient...', 1000000n], // 1 USDC(6 位小数)
});
await pilot.execute({
to: '0xUSDC_ADDRESS...',
data,
chainId: 1,
});
获取交易历史记录。
const state = pilot.getState();
console.log('当前有效权限:', state.permissions);
// 或通过 API 查询
const response = await fetch('https://api.walletpilot.xyz/v1/tx/history/PERMISSION_ID', {
headers: { 'Authorization': 'Bearer wp_...' },
});
const { data } = await response.json();
console.log('近期交易:', data);
| 权限名称 | 示例 | 说明 |
|---|---|---|
spend |
{ token: 'USDC', limit: '100', period: 'day' } |
每个周期内允许的最大代币支出额度 |
chains |
[1, 137, 42161] |
允许操作的链 ID 列表 |
contracts |
['0x...'] |
允许交互的合约地址列表 |
expiry |
'30d' |
权限过期时间 |
| 链名称 | ID | 标识符 |
|---|---|---|
| Ethereum | 1 | mainnet |
| Polygon | 137 | polygon |
| Arbitrum | 42161 | arbitrum |
| Optimism | 10 | optimism |
| Base | 8453 | base |
基础 URL: https://api.walletpilot.xyz
| 端点 | HTTP 方法 | 说明 |
|---|---|---|
/v1/permissions/request |
POST | 申请新权限 |
/v1/permissions/:id |
GET | 获取权限详情 |
/v1/tx/execute |
POST | 执行交易 |
/v1/tx/:hash |
GET | 查询交易状态 |
import { WalletPilot, PermissionBuilder } from '@walletpilot/sdk';
async function defiAgent() {
const pilot = new WalletPilot({ apiKey: process.env.WALLETPILOT_KEY });
// 检查是否已有有效权限
const state = pilot.getState();
if (!state.connected) {
// 请求权限
const permission = new PermissionBuilder()
.spend('USDC', '500', 'day')
.chains([1, 42161])
.expiry('7d')
.description('DeFi 交易 agent')
.build();
const { deepLink } = await pilot.requestPermission(permission);
console.log('请在 MetaMask 中确认授权:', deepLink);
return;
}
// 执行交易
const swapData = await getSwapQuote('USDC', 'ETH', '100');
await pilot.execute({
to: swapData.to,
data: swapData.data,
chainId: 1,
});
console.log('兑换已执行!');
}
相关专题
热门下载
相关下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 134.1万人学习
共49课时 | 82.6万人学习
最新文章