跳到主要内容

解绑推荐码

解除当前用户与推荐人的绑定关系。

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

请求体

{
"signature": "0x...",
"timestamp": 1772010600
}
字段类型必填说明
signaturestringEIP-712 签名
timestampuint64Unix 时间戳(秒),必须在 5 分钟内

EIP-712 签名

TypeHash: UnbindReferralCode(address wallet,uint256 timestamp)
{
"primaryType": "UnbindReferralCode",
"types": {
"UnbindReferralCode": [
{ "name": "wallet", "type": "address" },
{ "name": "timestamp", "type": "uint256" }
]
},
"message": {
"wallet": "0x<your_address>",
"timestamp": 1772010600
}
}

响应

{
"success": true,
"previous_referrer": "0x29f721b203a9fc9c5dde35a739d8b8e0e4605489",
"previous_code": "4DDDC2D4"
}
字段类型说明
successbool是否解绑成功
previous_referrerstring之前的推荐人钱包地址
previous_codestring之前绑定的推荐码

错误码

HTTP错误码说明
400NOT_BOUND当前未绑定任何推荐码
400TIMESTAMP_EXPIRED时间戳超过 5 分钟有效期
401SIGNATURE_INVALIDEIP-712 签名验证失败
500UNBIND_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())

typed_data = {
"types": {
"EIP712Domain": [
{"name": "name", "type": "string"},
{"name": "version", "type": "string"},
{"name": "chainId", "type": "uint256"},
],
"UnbindReferralCode": [
{"name": "wallet", "type": "address"},
{"name": "timestamp", "type": "uint256"},
],
},
"primaryType": "UnbindReferralCode",
"domain": {"name": "ZTDX", "version": "1", "chainId": 421614},
"message": {"wallet": wallet.address, "timestamp": timestamp},
}

signable = encode_typed_data(full_message=typed_data)
signed = wallet.sign_message(signable)

resp = requests.post(
f"{BASE_URL}/referral/unbind",
headers={"Authorization": f"Bearer {JWT_TOKEN}", "Content-Type": "application/json"},
json={"signature": signed.signature.hex(), "timestamp": timestamp},
)
print(resp.json())
# {"success": true, "previous_referrer": "0x29f7...5489", "previous_code": "4DDDC2D4"}