认证方式
所有受保护接口需要通过以下任意一种方式传递 API Key:
方式一:请求头 X-Api-Key
X-Api-Key: your_api_key_here
方式二:Authorization Bearer
Authorization: Bearer your_api_key_here
API Key 在管理后台 设置页面 生成和管理。
获取账户列表 需认证
返回所有已授权的钱包地址及其 USDT / USDC / ETH 余额与授权额度。
请求参数
无
请求示例
cURL
curl -X GET https://your-domain.com/api/wallets/list \ -H "X-Api-Key: your_api_key_here"
响应示例
{
"wallets": [
{
"address": "0xUserWalletAddress...",
"owner": "0xDeployerAddress...",
"addedAt": "2025-01-01T00:00:00.000Z",
"ethBalance": "0.5",
"usdtBalance": "1000.000000",
"usdtAllowance": "115792089237316195423570985008687907853269984665640564039457.584007913129639935",
"usdcBalance": "500.000000",
"usdcAllowance": "0.000000"
}
]
}字段说明(wallets 数组元素)
| 字段 | 类型 | 说明 |
|---|---|---|
| address | string | 钱包地址(已授权的用户) |
| owner | string | 授权操作发起方 |
| addedAt | string | 授权时间(ISO 8601) |
| ethBalance | string | ETH 余额(单位:ETH) |
| usdtBalance | string | USDT 余额(单位:USDT,6位小数) |
| usdtAllowance | string | USDT 对合约的授权额度 |
| usdcBalance | string | USDC 余额(单位:USDC,6位小数) |
| usdcAllowance | string | USDC 对合约的授权额度 |
执行转账 需认证
从指定钱包地址将 USDT 或 USDC 转账到目标地址。
前提: 用户已完成链上 approve(授权额度 ≥ 转账金额)。
请求参数(JSON Body)
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| token | string | 是 | 代币合约地址(USDT 或 USDC) |
| from | string | 是 | 来源钱包地址(已授权用户) |
| to | string | 是 | 目标收款地址 |
| amount | string | 是 | 转账金额(人类可读单位,如 "100.5") |
请求示例
cURL
curl -X POST https://your-domain.com/api/wallets/withdraw \
-H "Content-Type: application/json" \
-H "X-Api-Key: your_api_key_here" \
-d '{
"token": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
"from": "0xUserWalletAddress...",
"to": "0xRecipientAddress...",
"amount": "100"
}'响应示例
{
"success": true,
"txHash": "0xTransactionHash..."
}错误码
| HTTP 状态 | message | 原因 |
|---|---|---|
| 400 | 参数不完整 | 缺少必填字段 |
| 401 | 请先登录或提供有效的 API Key | 未认证 |
| 500 | (合约错误信息) | 余额不足、未授权等链上错误 |
用户授权流程
完整对接需要以下步骤:
- 调用添加账户接口 —
POST /api/wallets/authorize
将用户钱包地址注册到合约。 - 引导用户完成链上 approve
将用户引导至授权页:// USDT 授权(无限额度) https://your-domain.com/authorize/usdt // USDC 授权(指定 100 USDC) https://your-domain.com/authorize/usdc?amount=100
?amount=100— 授权固定金额(单位:代币)- 不传 amount — 默认无限授权
- 查询账户列表 —
GET /api/wallets/list
确认usdtAllowance/usdcAllowance大于 0。 - 执行转账 —
POST /api/wallets/withdraw