跳到主要内容

绑定推荐码

将当前用户(Trader)绑定到指定推荐码的推荐人下。已绑定的用户可重新绑定以切换推荐人。

POST /referral/bind
Authorization: Bearer <token>
Content-Type: application/json

请求体

{
"code": "4DDDC2D4",
"signature": "0x...",
"timestamp": 1772010600
}
字段类型必填说明
codestring要绑定的推荐码
signaturestringEIP-712 签名
timestampuint64Unix 时间戳(秒),必须在 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"
}
字段类型说明
successbool是否绑定成功
referrer_addressstring推荐人钱包地址
referrer_codestring绑定的推荐码

错误码

HTTP错误码说明
400TIMESTAMP_EXPIRED时间戳超过 5 分钟有效期
400SELF_REFERRAL不能使用自己的推荐码
400SAME_REFERRER已绑定该推荐人
401SIGNATURE_INVALIDEIP-712 签名验证失败
404CODE_NOT_FOUND推荐码不存在
500BIND_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"}