建立代理錢包
每個代理都有自己的 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"
刪除前請確保錢包餘額為零。刪除後任何剩餘資金將無法存取。