AgentWallex logo
文档

快速开始

5 分钟内集成 AgentWallex

概述

AgentWallex 为 AI Agent 提供 MPC 安全钱包,使其无需暴露私钥即可在链上交易。本指南将引导你完成首个 Agent 钱包的设置。

前置条件

  • Node.js 18+ 或 Python 3.9+
  • AgentWallex API 密钥(awx_...)(申请早期访问
  • 基本的区块链交易知识

安装

安装 TypeScript SDK:

npm install @agentwallex/sdk

或者 Python:

pip install agentwallex

快速开始

1. 初始化客户端

import { AgentWallex } from "@agentwallex/sdk";
 
const aw = new AgentWallex({
  apiKey: process.env.AGENTWALLEX_API_KEY!,
  environment: "sandbox", // 生产环境使用 "production"
});

2. 创建 Agent 钱包

const agent = await aw.agents.create({
  name: "my-trading-agent",
  chain: "eip155:84532",
  policies: {
    maxTransactionAmount: "100", // USDC
    dailyLimit: "1000",
    allowedAddresses: ["0x..."],
  },
});
 
console.log(`Agent ID: ${agent.id}`);
console.log(`钱包地址: ${agent.wallet.address}`);

3. 执行支付

const tx = await aw.payments.send({
  agentId: agent.id,
  to: "0xRecipientAddress",
  amount: "10.00",
  token: "USDC",
});
 
console.log(`交易哈希: ${tx.hash}`);
console.log(`状态: ${tx.status}`); // "confirmed"

底层机制

  1. 策略检查 — 策略引擎根据 Agent 的规则验证交易
  2. MPC 签名 — 使用 2-of-3 门限 MPC 签名交易(任何一方都无法获取完整密钥)
  3. 广播 — 签名后的交易提交到网络
  4. 确认 — AgentWallex 监控并确认交易

下一步