Skip to main content

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
}
FieldTypeRequiredDescription
codestringYesThe referral code to bind to
signaturestringYesEIP-712 signature
timestampuint64YesUnix 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"
}
FieldTypeDescription
successboolWhether binding succeeded
referrer_addressstringThe referrer's wallet address
referrer_codestringThe referral code that was bound

Error Codes

HTTPCodeDescription
400TIMESTAMP_EXPIREDTimestamp exceeds 5-minute validity window
400SELF_REFERRALCannot use your own referral code
400SAME_REFERRERAlready bound to this referrer
401SIGNATURE_INVALIDEIP-712 signature verification failed
404CODE_NOT_FOUNDReferral code does not exist
500BIND_FAILEDServer 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"}