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

# 代理錢包

> 了解 Polymarket 代理錢包的工作原理和優勢

Polymarket 的代理錢包（Proxy Wallet）是一個智能合約錢包系統，為用戶提供簡化的交易體驗。

<Callout type="success">
  還沒有帳號？[點擊這裡註冊 Polymarket](https://polymarket.com/?r=2026VIP) 並完成入金，才能用錢包私鑰為訂單籤名、實際成交。
</Callout>

<Warning>
  **法律合規提醒**：在使用 Polymarket 服務或 API 前，請確認您所在地區的法律規定。Polymarket 目前不支援比利時、法國、新加坡、泰國、中國大陸等地區，政策可能隨時變化。
</Warning>

## 什麼是代理錢包？

代理錢包是 Polymarket 為每個用戶創建的智能合約錢包，位於用戶的外部錢包（如 MetaMask）和交易系統之間。

```
用戶錢包 → 代理錢包 → Polymarket 合約
(MetaMask)  (智能合約)   (CTF/CLOB)
```

## 工作原理

當你首次在 Polymarket 進行交易時：

1. **自動創建**：系統為你創建一個代理錢包合約
2. **資金轉移**：你將 USDC 存入代理錢包
3. **授權交易**：代理錢包已預先授權 Polymarket 合約
4. **無縫交易**：之後的交易無需重複授權

<CardGroup cols={2}>
  <Card title="用戶友好" icon="user">
    一次設置，永久使用
  </Card>

  <Card title="Gas 優化" icon="gauge">
    減少鏈上交易次數
  </Card>

  <Card title="安全可靠" icon="shield">
    智能合約保證安全
  </Card>

  <Card title="無需授權" icon="check">
    不需要每次批准 USDC 使用
  </Card>
</CardGroup>

## 優勢

### 1. 簡化用戶體驗

**傳統方式（EOA）**：

```
1. 批准 USDC 授權 → Gas 費用
2. 下單 → Gas 費用
3. 每次交易都需要籤名
4. 需要管理授權額度
```

**代理錢包方式**：

```
1. 首次存款自動設置
2. 之後交易無需額外授權
3. 一次籤名即可
4. 自動管理授權
```

### 2. 降低 Gas 成本

代理錢包預先授權了必要的合約，避免每次交易都需要授權交易：

| 操作   | EOA    | 代理錢包  | 節省     |
| ---- | ------ | ----- | ------ |
| 首次交易 | 2 筆交易  | 1 筆交易 | 50%    |
| 後續交易 | 需要檢查授權 | 無需授權  | Gas 更低 |

### 3. 更好的安全性

* ✅ 合約經過審計
* ✅ 資金始終在你的控制下
* ✅ 可以隨時提取
* ✅ 不會暴露主錢包私鑰

### 4. 支援社交登錄

代理錢包使得以下登錄方式成為可能：

* 📧 Email/Magic Link
* 🌐 Google 帳戶
* 🍎 Apple ID
* 🐦 Twitter/X

## 代理錢包地址

你的代理錢包地址可以在 Polymarket 網站上找到：

1. 登錄 Polymarket
2. 點擊右上角的個人資料圖片
3. 代理地址顯示在你的頭像下方

```
你的地址: 0x1234... (主錢包)
代理地址: 0x5678... (用於交易)
```

## 技術實現

### 合約架構

代理錢包使用 Gnosis Safe 或類似的多籤架構：

```solidity theme={null}
// 代理錢包合約（簡化）
contract ProxyWallet {
    address public owner;          // 用戶地址
    address public polymarket;     // Polymarket 系統
    
    // 預先授權的合約
    mapping(address => bool) public authorizedContracts;
    
    function executeTransaction(
        address target,
        bytes calldata data
    ) external {
        require(msg.sender == owner || msg.sender == polymarket);
        require(authorizedContracts[target]);
        // 執行交易
    }
}
```

### 創建過程

```javascript theme={null}
// 用戶首次存款時
const createProxyWallet = async (userAddress) => {
  // 1. 部署代理錢包合約
  const proxy = await deployProxy(userAddress);
  
  // 2. 設置授權
  await proxy.authorize(CTF_CONTRACT);
  await proxy.authorize(CLOB_CONTRACT);
  
  // 3. 返回代理地址
  return proxy.address;
};
```

## 使用代理錢包進行 API 交易

### Python 示例

```python theme={null}
from py_clob_client.client import ClobClient

# 使用代理錢包
client = ClobClient(
    host="https://clob.polymarket.com",
    key=private_key,           # 你的主錢包私鑰
    chain_id=137,
    signature_type=1,          # Magic/Email 登錄使用 1
    funder=proxy_address       # 你的代理錢包地址
)

# 設置 API 憑據
client.set_api_creds(client.create_or_derive_api_creds())

# 現在可以直接交易，無需額外授權
order = client.create_order(OrderArgs(
    price=0.55,
    size=100,
    side=BUY,
    token_id="YOUR_TOKEN_ID"
))

client.post_order(order, OrderType.GTC)
```

### TypeScript 示例

```typescript theme={null}
import { ClobClient } from '@polymarket/clob-client';
import { ethers } from 'ethers';

const wallet = new ethers.Wallet(privateKey);

// 使用代理錢包
const client = new ClobClient(
  'https://clob.polymarket.com',
  137,
  wallet,
  1,              // Magic/Email 登錄使用 1
  proxyAddress    // 代理錢包地址
);

// 交易無需額外授權步驟
await client.setApiCreds(client.createOrDeriveApiCreds());
```

## 籤名類型

根據帳戶創建方式，使用不同的籤名類型：

| 登錄方式        | 籤名類型 | Funder | 說明         |
| ----------- | ---- | ------ | ---------- |
| Email/Magic | `1`  | 代理地址   | 通過郵件登錄     |
| 瀏覽器錢包       | `2`  | 代理地址   | MetaMask 等 |
| EOA         | `0`  | -      | 高級用戶直接使用   |

## 資金管理

### 存款到代理錢包

```python theme={null}
# 存款會自動轉到代理錢包
# 通過 Polymarket 網站的 Deposit 功能
```

### 從代理錢包提款

```python theme={null}
# 提款也通過 Polymarket 網站
# 資金會返回到你的主錢包
```

### 查詢代理錢包餘額

```python theme={null}
# 使用 CLOB 客戶端
balance = client.get_balance()
print(f"代理錢包餘額: {balance} USDC")
```

## 安全考慮

<Warning>
  **重要提示**：

  1. **私鑰安全**：代理錢包仍需要你的私鑰籤名
  2. **授權管理**：定期檢查代理錢包的授權
  3. **及時提款**：不使用時可以提款到主錢包
  4. **合約風險**：雖然經過審計，但智能合約仍有風險
</Warning>

### 檢查授權

```python theme={null}
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://polygon-rpc.com'))

# USDC 合約
usdc_contract = w3.eth.contract(
    address='0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
    abi=usdc_abi
)

# 檢查代理錢包的 USDC 授權
allowance = usdc_contract.functions.allowance(
    proxy_address,
    ctf_contract_address
).call()

print(f"授權額度: {allowance / 10**6} USDC")
```

## 與 EOA 的對比

| 特性     | 代理錢包  | EOA |
| ------ | ----- | --- |
| 用戶體驗   | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
| Gas 成本 | 低     | 中   |
| 設置複雜度  | 低     | 高   |
| 靈活性    | 中     | 高   |
| 社交登錄   | ✅     | ❌   |
| 需要授權   | 首次    | 每次  |
| 控制權    | 完全    | 完全  |

## 常見問題

### Q: 代理錢包地址和我的錢包地址是一樣的嗎？

A: 不是。代理錢包是單獨的智能合約地址，但你完全控制它。

### Q: 如果我換了主錢包怎麼辦？

A: 代理錢包綁定到你的帳戶，不是綁定到特定錢包。可以聯繫支援團隊。

### Q: 代理錢包會被黑客攻擊嗎？

A: 代理錢包經過審計，且你的資金始終在你控制下。使用正常的安全措施即可。

### Q: 可以不使用代理錢包嗎？

A: 可以，但需要使用 EOA 模式，需要更多手動設置。

### Q: 代理錢包的 Gas 費用由誰支付？

A: 由你支付，但代理錢包優化了 Gas 使用，總體更便宜。

## 故障排除

### 問題：找不到代理地址

**解決方案**：

1. 確保已經在 Polymarket 完成過至少一次交易
2. 檢查 Polymarket 網站的個人資料頁面
3. 聯繫支援團隊

### 問題：籤名類型錯誤

**解決方案**：
確認你的登錄方式：

* Email 登錄 → 使用 `signature_type=1`
* MetaMask 登錄 → 使用 `signature_type=2`

### 問題：餘額顯示不正確

**解決方案**：

1. 刷新頁面或重新查詢
2. 檢查是否在正確的網絡（Polygon）
3. 等待區塊確認

## 下一步

<CardGroup cols={2}>
  <Card title="CLOB 認證" icon="key" href="/api-tutorial/clob/authentication">
    了解如何使用代理錢包認證
  </Card>

  <Card title="第一筆訂單" icon="rocket" href="/api-tutorial/first-order">
    使用代理錢包下訂單
  </Card>

  <Card title="條件代幣框架" icon="code" href="/api-tutorial/conditional-tokens/overview">
    理解底層機制
  </Card>

  <Card title="安全最佳實踐" icon="shield" href="/get-started/faq">
    保護你的帳戶
  </Card>
</CardGroup>
