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

# 预充值账户

> 使用预充值余额启用即时交易执行

## 概览

预充值账户允许您与 KillB 保持余额，以便即时执行交易，而无需等待支付确认。

<Info>
  预充值账户提供最快的交易体验，非常适合高交易量操作。
</Info>

## 优势

<CardGroup cols={2}>
  <Card title="即时执行" icon="bolt">
    交易立即执行，无支付延迟
  </Card>

  <Card title="更好的汇率" icon="tag">
    预充值交易的费用降低
  </Card>

  <Card title="简化流程" icon="diagram-project">
    无需支付 URL 或确认
  </Card>

  <Card title="可预测的结算" icon="clock">
    准确知道资金何时到达
  </Card>
</CardGroup>

## 工作原理

<Steps>
  <Step title="创建预充值账户">
    为您的货币/网络请求专用账户
  </Step>

  <Step title="存入资金">
    将资金转移到提供的地址/账户
  </Step>

  <Step title="检查余额">
    验证您的预充值余额
  </Step>

  <Step title="创建 Ramps">
    在报价中使用预充值方式
  </Step>

  <Step title="即时执行">
    Ramps 立即从您的余额中执行
  </Step>
</Steps>

## 创建预充值账户

```bash theme={null}
POST /api/v2/customers/pre-fund/create
```

<CodeGroup>
  ```json 加密货币预充值 theme={null}
  {
    "currency": "USDC",
    "network": "POLYGON"
  }
  ```

  ```javascript Node.js theme={null}
  const createPreFundAccount = async (currency, network) => {
    const response = await fetch(
      'https://sandbox.killb.app/api/v2/customers/pre-fund/create',
      {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${token}`,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          currency,
          network
        })
      }
    );
    
    const account = await response.json();
    console.log('Deposit address:', account.address);
    return account;
  };

  // 创建 Polygon 上的 USDC 预充值账户
  const preFund = await createPreFundAccount('USDC', 'POLYGON');
  ```

  ```python Python theme={null}
  def create_prefund_account(currency, network, access_token):
      response = requests.post(
          'https://sandbox.killb.app/api/v2/customers/pre-fund/create',
          headers={
              'Authorization': f'Bearer {access_token}',
              'Content-Type': 'application/json'
          },
          json={
              'currency': currency,
              'network': network
          }
      )
      account = response.json()
      print(f"Deposit to: {account['address']}")
      return account
  ```
</CodeGroup>

**响应：**

```json theme={null}
{
  "id": "prefund-account-id",
  "type": "PRE_FUND",
  "address": "0xABC...DEF",
  "currency": "USDC",
  "network": "POLYGON",
  "active": true,
  "createdAt": "2024-01-15T10:30:00.000Z"
}
```

## 支持的预充值方式

**加密货币：**

* `PRE_FUND_POLYGON` - Polygon 上的 USDC/USDT
* `PRE_FUND_ERC20` - Ethereum 上的 USDC/USDT
* `PRE_FUND_SOLANA` - Solana 上的 USDC/USDT
* `PRE_FUND_TRON` - Tron 上的 USDC/USDT
* `PRE_FUND_ARBITRUM` - Arbitrum 上的 USDC/USDT

**法币：**

* `PRE_FUND` - USD, COP, MXN 法币余额

## 在 Ramps 中使用预充值

在报价中指定预充值方式：

```json theme={null}
{
  "fromCurrency": "USDC",
  "toCurrency": "COP",
  "amount": 100,
  "amountIsToCurrency": false,
  "cashInMethod": "PRE_FUND_POLYGON",
  "cashOutMethod": "PSE"
}
```

如果您有足够的预充值余额，ramp 将立即执行。

## 检查余额

获取您的预充值余额：

```bash theme={null}
GET /api/v2/customers/balances
```

```json 响应 theme={null}
[
  {
    "id": "balance-id",
    "currency": "USDC",
    "amount": "1000.50",
    "accountId": "prefund-account-id"
  },
  {
    "id": "balance-id-2",
    "currency": "COP",
    "amount": "5000000.00",
    "accountId": "prefund-fiat-id"
  }
]
```

```javascript theme={null}
const getPreFundBalance = async () => {
  const response = await fetch(
    'https://sandbox.killb.app/api/v2/customers/balances',
    {
      headers: {
        'Authorization': `Bearer ${token}`
      }
    }
  );
  
  const balances = await response.json();
  
  // 查找 USDC 余额
  const usdcBalance = balances.find(b => b.currency === 'USDC');
  console.log('USDC Balance:', usdcBalance.amount);
  
  return balances;
};
```

## 存入资金

### 加密货币存款

将 USDC/USDT 发送到预充值账户地址：

```javascript theme={null}
// 使用 ethers.js
const depositToPreFund = async (amount) => {
  const preFundAccount = await getPreFundAccount('USDC', 'POLYGON');
  const usdcContract = new ethers.Contract(USDC_ADDRESS, ERC20_ABI, signer);
  
  // 发送 USDC
  const tx = await usdcContract.transfer(
    preFundAccount.address,
    ethers.utils.parseUnits(amount.toString(), 6) // USDC 有 6 位小数
  );
  
  await tx.wait();
  console.log('Deposit confirmed:', tx.hash);
};
```

### 法币存款

联系支持以通过电汇或 ACH 安排法币预充值。

## 最佳实践

<AccordionGroup>
  <Accordion title="监控余额" icon="gauge">
    ```javascript theme={null}
    const checkBeforeRamp = async (requiredAmount) => {
      const balances = await getPreFundBalance();
      const usdcBalance = parseFloat(balances.find(b => b.currency === 'USDC').amount);
      
      if (usdcBalance < requiredAmount) {
        throw new Error(`余额不足。需要 ${requiredAmount}，现有 ${usdcBalance}`);
      }
    };
    ```
  </Accordion>

  <Accordion title="设置低余额警报" icon="bell">
    ```javascript theme={null}
    const balance = await getPreFundBalance();
    const threshold = 1000; // 在 $1000 时警报

    if (balance.amount < threshold) {
      await sendAlert('预充值余额低', balance);
    }
    ```
  </Accordion>

  <Accordion title="定期对账" icon="calculator">
    * 跟踪所有存款
    * 监控所有使用预充值的 ramps
    * 计算预期余额
    * 与实际余额比较
    * 调查差异
  </Accordion>
</AccordionGroup>

## 下一步

<CardGroup cols={2}>
  <Card title="检查流动性" icon="chart-line" href="/api-reference/endpoint/customers-liquidity">
    查看您的可用流动性
  </Card>

  <Card title="创建 Ramps" icon="arrow-right-arrow-left" href="/zh/guides/ramps/overview">
    在 ramp 交易中使用预充值
  </Card>
</CardGroup>
