建立代理錢包
每個代理都有自己的 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}`);
agent = await aw.agents.create(
name="payment-agent",
chain="eip155:8453",
policies={
"max_transaction_amount": "500",
"daily_limit": "5000",
"allowed_tokens": ["USDC"],
},
metadata={"team": "growth"},
)
print(f"Agent ID: {agent.id}")
print(f"Wallet address: {agent.wallet.address}")
curl -X POST https://api.agentwallex.com/api/v1/agents \
-H "X-API-Key: awx_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"agent_name": "payment-agent",
"chain": "eip155:8453",
"metadata": "{\"team\":\"growth\"}"
}'
為錢包注資
向代理的錢包地址發送代幣。錢包地址是標準的鏈上地址,可以從任何來源接收代幣。在沙箱模式(
eip155:84532)下,使用測試網水龍頭取得測試代幣。不需要真實資金。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
tx = await aw.payments.send(
agent_id="agent_abc123",
to="0xRecipientAddress",
amount="50.00",
token="USDC",
memo="Payment for API access",
)
print(f"Hash: {tx.hash}")
print(f"Status: {tx.status}")
curl -X POST https://api.agentwallex.com/api/v1/transactions \
-H "X-API-Key: awx_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "agent_abc123",
"direction": "outbound",
"type": "transfer",
"to_address": "0xRecipientAddress",
"amount": "50.00",
"token": "USDC",
"chain": "eip155:8453",
"memo": "Payment for API access"
}'
查詢餘額
查詢代理的 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})`);
});
curl -X GET "https://api.agentwallex.com/api/v1/transactions?agent_id=agent_abc123&status=confirmed&page_size=50" \
-H "X-API-Key: awx_your_api_key"
凍結與解凍
立即停止代理的所有交易。適用於緊急情況或排程維護。凍結
await aw.agents.freeze("agent_abc123");
// All transactions are now blocked
curl -X PUT https://api.agentwallex.com/api/v1/agents/agent_abc123/status \
-H "X-API-Key: awx_your_api_key" \
-H "Content-Type: application/json" \
-d '{"status": "inactive"}'
解凍
// Subject to 10-minute cool-down after freeze
await aw.agents.unfreeze("agent_abc123");
curl -X PUT https://api.agentwallex.com/api/v1/agents/agent_abc123/status \
-H "X-API-Key: awx_your_api_key" \
-H "Content-Type: application/json" \
-d '{"status": "active"}'
凍結後有強制 10 分鐘冷卻期才能解凍。嘗試提前解凍將回傳錯誤。
刪除代理
永久刪除代理及其錢包。此操作不可逆。curl -X DELETE https://api.agentwallex.com/api/v1/agents/agent_abc123 \
-H "X-API-Key: awx_your_api_key"
刪除前請確保錢包餘額為零。刪除後任何剩餘資金將無法存取。