Bind Referral Code
Bind the current user (Trader) to a referrer via their referral code. Users who are already bound can rebind to switch referrers.
POST /referral/bind
Authorization: Bearer <token>
Content-Type: application/json
Request Body
{
"code": "4DDDC2D4",
"signature": "0x...",
"timestamp": 1772010600
}
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | The referral code to bind to |
signature | string | Yes | EIP-712 signature |
timestamp | uint64 | Yes | Unix timestamp (seconds), must be within 5 minutes |
EIP-712 Signature
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
}
}
Response
{
"success": true,
"referrer_address": "0x29f721b203a9fc9c5dde35a739d8b8e0e4605489",
"referrer_code": "4DDDC2D4"
}
| Field | Type | Description |
|---|---|---|
success | bool | Whether binding succeeded |
referrer_address | string | The referrer's wallet address |
referrer_code | string | The referral code that was bound |
Error Codes
| HTTP | Code | Description |
|---|---|---|
| 400 | TIMESTAMP_EXPIRED | Timestamp exceeds 5-minute validity window |
| 400 | SELF_REFERRAL | Cannot use your own referral code |
| 400 | SAME_REFERRER | Already bound to this referrer |
| 401 | SIGNATURE_INVALID | EIP-712 signature verification failed |
| 404 | CODE_NOT_FOUND | Referral code does not exist |
| 500 | BIND_FAILED | Server error |
Code Examples
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"}