绑定推荐码
将当前用户(Trader)绑定到指定推荐码的推荐人下。已绑定的用户可重新绑定以切换推荐人。
POST /referral/bind
Authorization: Bearer <token>
Content-Type: application/json
请求体
{
"code": "4DDDC2D4",
"signature": "0x...",
"timestamp": 1772010600
}
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
code | string | 是 | 要绑定的推荐码 |
signature | string | 是 | EIP-712 签名 |
timestamp | uint64 | 是 | Unix 时间戳(秒),必须在 5 分钟内 |
EIP-712 签名
TypeHash: BindReferralCode(address wallet,string code,uint256 timestamp)
{
"primaryType": "BindReferralCode",
"types": {
"BindReferralCode": [
{ "name": "wallet", "type": "address" },
{ "name": "code", "type": "string" },
{ "name": "timestamp", "type": "uint256" }
]
},
"message": {
"wallet": "0x<your_address>",
"code": "4DDDC2D4",
"timestamp": 1772010600
}
}
响应
{
"success": true,
"referrer_address": "0x29f721b203a9fc9c5dde35a739d8b8e0e4605489",
"referrer_code": "4DDDC2D4"
}
| 字段 | 类型 | 说明 |
|---|---|---|
success | bool | 是否绑定成功 |
referrer_address | string | 推荐人钱包地址 |
referrer_code | string | 绑定的推荐码 |
错误码
| HTTP | 错误码 | 说明 |
|---|---|---|
| 400 | TIMESTAMP_EXPIRED | 时间戳超过 5 分钟有效期 |
| 400 | SELF_REFERRAL | 不能使用自己的推荐码 |
| 400 | SAME_REFERRER | 已绑定该推荐人 |
| 401 | SIGNATURE_INVALID | EIP-712 签名验证失败 |
| 404 | CODE_NOT_FOUND | 推荐码不存在 |
| 500 | BIND_FAILED | 服务端错误 |
代码示例
Python
import time, requests
from eth_account import Account
from eth_account.messages import encode_typed_data
BASE_URL = "https://api.ztdx.io"
JWT_TOKEN = "your_jwt_token"
PRIVATE_KEY = "your_private_key"
wallet = Account.from_key(PRIVATE_KEY)
timestamp = int(time.time())
code = "4DDDC2D4"
typed_data = {
"types": {
"EIP712Domain": [
{"name": "name", "type": "string"},
{"name": "version", "type": "string"},
{"name": "chainId", "type": "uint256"},
],
"BindReferralCode": [
{"name": "wallet", "type": "address"},
{"name": "code", "type": "string"},
{"name": "timestamp", "type": "uint256"},
],
},
"primaryType": "BindReferralCode",
"domain": {"name": "ZTDX", "version": "1", "chainId": 421614},
"message": {"wallet": wallet.address, "code": code, "timestamp": timestamp},
}
signable = encode_typed_data(full_message=typed_data)
signed = wallet.sign_message(signable)
resp = requests.post(
f"{BASE_URL}/referral/bind",
headers={"Authorization": f"Bearer {JWT_TOKEN}", "Content-Type": "application/json"},
json={"code": code, "signature": signed.signature.hex(), "timestamp": timestamp},
)
print(resp.json())
# {"success": true, "referrer_address": "0x29f7...5489", "referrer_code": "4DDDC2D4"}