> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentwallex.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 钱包操作

> 创建钱包、充值、发送支付、查询余额和管理代理状态。

## 创建代理钱包

每个代理都有自己的 MPC 安全钱包。在创建时指定链和初始策略。

<CodeGroup>
  ```typescript TypeScript theme={null}
  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}`);
  ```

  ```python Python theme={null}
  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}")
  ```

  ```bash cURL theme={null}
  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\"}"
    }'
  ```
</CodeGroup>

## 为钱包充值

向代理的钱包地址发送代币。钱包地址是标准的链上地址，可以从任何来源接收代币。

<Note>
  在沙盒模式下（`eip155:84532`），使用测试网水龙头获取测试代币。无需真实资金。
</Note>

对于 x402 操作，您还可以通过余额端点充值：

```bash theme={null}
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 签名。

<CodeGroup>
  ```typescript TypeScript theme={null}
  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
  ```

  ```python Python theme={null}
  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}")
  ```

  ```bash cURL theme={null}
  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"
    }'
  ```
</CodeGroup>

## 查询余额

查询代理的 x402 余额：

```bash theme={null}
curl -X GET https://api.agentwallex.com/api/v1/x402/balances \
  -H "X-API-Key: awx_your_api_key"
```

## 列出交易

查看代理的交易历史：

<CodeGroup>
  ```typescript TypeScript theme={null}
  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})`);
  });
  ```

  ```bash cURL theme={null}
  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"
  ```
</CodeGroup>

## 冻结和解冻

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

### 冻结

<CodeGroup>
  ```typescript TypeScript theme={null}
  await aw.agents.freeze("agent_abc123");
  // All transactions are now blocked
  ```

  ```bash cURL theme={null}
  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"}'
  ```
</CodeGroup>

### 解冻

<CodeGroup>
  ```typescript TypeScript theme={null}
  // Subject to 10-minute cool-down after freeze
  await aw.agents.unfreeze("agent_abc123");
  ```

  ```bash cURL theme={null}
  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"}'
  ```
</CodeGroup>

<Warning>
  冻结后有强制 10 分钟的冷却期才能解冻。提前尝试解冻将返回错误。
</Warning>

## 删除代理

永久删除代理及其钱包。此操作不可逆。

```bash theme={null}
curl -X DELETE https://api.agentwallex.com/api/v1/agents/agent_abc123 \
  -H "X-API-Key: awx_your_api_key"
```

<Warning>
  删除前请确保钱包余额为零。删除后任何剩余资金将无法访问。
</Warning>
