安裝
用戶端初始化
| 參數 | 型別 | 預設值 | 說明 |
|---|---|---|---|
apiKey | string | 必填 | 您的 API 金鑰(awx_...) |
environment | "sandbox" | "production" | "sandbox" | 目標環境 |
baseUrl | string | — | 自訂基礎 URL(覆寫 environment) |
timeout | number | 30000 | 請求逾時(毫秒) |
代理
aw.agents.create(params)
建立具有 MPC 安全錢包的新代理。
| 欄位 | 型別 | 說明 |
|---|---|---|
id | string | 唯一代理識別碼 |
name | string | 代理顯示名稱 |
wallet.address | string | 鏈上錢包地址 |
wallet.chain | string | CAIP-2 鏈識別碼 |
status | string | "active" 或 "frozen" |
createdAt | string | ISO 8601 時間戳記 |
aw.agents.get(agentId)
透過 ID 擷取代理。
aw.agents.list(params?)
列出您帳戶中的所有代理。
aw.agents.freeze(agentId)
立即凍結代理的錢包,阻止所有交易。
aw.agents.unfreeze(agentId)
在凍結後重新啟用代理的錢包(受 10 分鐘冷卻期限制)。
付款
aw.payments.send(params)
發送直接鏈上付款。
| 欄位 | 型別 | 說明 |
|---|---|---|
id | string | 交易 ID |
hash | string | 鏈上交易雜湊 |
status | string | "pending"、"confirmed"、"failed" |
amount | string | 發送金額 |
token | string | 代幣符號 |
fee | string | 已支付的網路 gas 費用 |
aw.payments.get(transactionId)
取得交易詳情和狀態。
aw.payments.list(params)
列出代理的交易。
x402 微型支付
aw.x402.createSession(params)
建立具有支出預算的 x402 付款工作階段。
aw.x402.check(params)
檢查目標 URL 是否支援 x402 付款協商。
aw.x402.pay(params)
協商並完成一筆 x402 付款。
aw.x402.sessionPay(sessionId, params)
使用現有工作階段預算付款。
aw.x402.httpInterceptor(params)
建立自動處理 x402 v2 挑戰的 HTTP fetch 包裝器:
- 從 402 回應中讀取
PAYMENT-REQUIRED標頭 - 透過 AgentWallex 提交付款
- 使用
PAYMENT-SIGNATURE標頭重試請求
策略
aw.policies.update(agentId, policies)
更新代理的支出策略。
aw.policies.get(agentId)
取得代理的當前策略。
aw.policies.applyTemplate(agentId, templateName)
將策略範本套用至代理。
aw.policies.createTemplate(name, rules)
建立可重複使用的策略範本。
Webhooks
aw.webhooks.create(params)
註冊 webhook 端點。
錯誤處理
SDK 提供型別化的錯誤類別:| 錯誤類別 | 觸發時機 |
|---|---|
AgentWallexError | 所有 API 錯誤的基礎類別 |
PolicyViolationError | 交易被策略引擎阻止 |
AuthenticationError | 無效或缺少 API 金鑰 |
NotFoundError | 資源不存在 |
RateLimitError | 超過速率限制 |