跳转到主要内容

创建代理钱包

每个代理都有自己的 MPC 安全钱包。在创建时指定链和初始策略。
const agent = await aw.agents.create({
  name: "payment-agent",
  chain: "eip155:8453",  // Base mainnet
  policies: {
    maxTransactionAmount: "500",
    dailyLimit: "5000",
    allowedTokens: ["USDC"],
  },
  metadata: { team: "growth" },
});

console.log(`Agent ID: ${agent.id}`);
console.log(`Wallet address: ${agent.wallet.address}`);
console.log(`Chain: ${agent.wallet.chain}`);

为钱包充值

向代理的钱包地址发送代币。钱包地址是标准的链上地址,可以从任何来源接收代币。
在沙盒模式下(eip155:84532),使用测试网水龙头获取测试代币。无需真实资金。
对于 x402 操作,您还可以通过余额端点充值:
curl -X POST https://api.agentwallex.com/api/v1/x402/balances/deposit-address \
  -H "X-API-Key: awx_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"agent_id": "agent_abc123", "chain": "eip155:8453"}'

发送支付

通过代理执行链上支付。交易在广播前会经过策略引擎和 MPC 签名。
const tx = await aw.payments.send({
  agentId: "agent_abc123",
  to: "0xRecipientAddress",
  amount: "50.00",
  token: "USDC",
  memo: "Payment for API access",
});

console.log(`Transaction ID: ${tx.id}`);
console.log(`Hash: ${tx.hash}`);
console.log(`Status: ${tx.status}`);   // "pending" -> "confirmed"
console.log(`Fee: ${tx.fee}`);         // Network gas fee

查询余额

查询代理的 x402 余额:
curl -X GET https://api.agentwallex.com/api/v1/x402/balances \
  -H "X-API-Key: awx_your_api_key"

列出交易

查看代理的交易历史:
const { transactions } = await aw.payments.list({
  agentId: "agent_abc123",
  limit: 50,
  status: "confirmed",
});

transactions.forEach(tx => {
  console.log(`${tx.amount} ${tx.token} -> ${tx.to} (${tx.status})`);
});

冻结和解冻

立即停止代理的所有交易。适用于紧急情况或计划维护。

冻结

await aw.agents.freeze("agent_abc123");
// All transactions are now blocked

解冻

// Subject to 10-minute cool-down after freeze
await aw.agents.unfreeze("agent_abc123");
冻结后有强制 10 分钟的冷却期才能解冻。提前尝试解冻将返回错误。

删除代理

永久删除代理及其钱包。此操作不可逆。
curl -X DELETE https://api.agentwallex.com/api/v1/agents/agent_abc123 \
  -H "X-API-Key: awx_your_api_key"
删除前请确保钱包余额为零。删除后任何剩余资金将无法访问。