Execute on-chain transactions with user-granted permissions. Built on MetaMask ERC-7715. No private keys, full guardrails.
通过MetaMask ERC-7715权限为AI代理赋予加密超能力。
WalletPilot使AI代理能够使用MetaMask的ERC-7715权限标准执行链上交易。用户一次性授予限定范围的权限(支出限额、链限制),代理即可在这些限制内自由执行操作。
主要特性:
向用户请求钱包权限。
typescript
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]) // 以太坊、Polygon、Arbitrum
.expiry(30d) // 有效期30天
.build();
const { deepLink } = await pilot.requestPermission(permission);
console.log(用户应打开:, deepLink);
使用已授予的权限执行交易。
typescript
const result = await pilot.execute({
to: 0x1234..., // 目标合约
data: 0xabcd..., // 调用数据(例如:兑换)
value: 0, // ETH金额(可选)
chainId: 1, // 链ID
});
console.log(交易哈希:, result.hash);
检查代币余额(使用标准RPC,无需权限)。
typescript
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聚合器执行代币兑换。
typescript
// 从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,
});
向地址发送代币。
typescript
import { encodeFunctionData, erc20Abi } from viem;
// 编码ERC20转账
const data = encodeFunctionData({
abi: erc20Abi,
functionName: transfer,
args: [0xRecipient..., 1000000n], // 1 USDC(6位小数)
});
await pilot.execute({
to: 0xUSDC_ADDRESS...,
data,
chainId: 1,
});
获取交易历史。
typescript
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 |
| 链 | ID | 名称 |
|---|---|---|
| 以太坊 | 1 | mainnet |
| Polygon |
基础URL: https://api.walletpilot.xyz
| 端点 | 方法 | 描述 |
|---|---|---|
| /v1/permissions/request | POST | 请求新权限 |
| /v1/permissions/:id |
typescript
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交易代理)
.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(兑换已执行!);
}
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 walletpilot-7715-1776365605 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 walletpilot-7715-1776365605 技能
skillhub install walletpilot-7715-1776365605
文件大小: 2.86 KB | 发布时间: 2026-4-17 15:09