Skip to main content

Create Referral Code

Generate a unique 8-character referral code (uppercase hex) for the current user. Each user can only create one code.

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

Request Body

{
"signature": "0x...",
"timestamp": 1772010600
}
FieldTypeRequiredDescription
signaturestringYesEIP-712 signature
timestampuint64YesUnix timestamp (seconds), must be within 5 minutes

EIP-712 Signature

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

Response

{
"success": true,
"code": "4DDDC2D4",
"created_at": 1772010604000
}
FieldTypeDescription
successboolWhether creation succeeded
codestringThe generated 8-character referral code
created_atint64Creation timestamp (milliseconds)

Error Codes

HTTPCodeDescription
400TIMESTAMP_EXPIREDTimestamp exceeds 5-minute validity window
400INVALID_SIGNATURE_FORMATSignature string format is invalid
401SIGNATURE_INVALIDEIP-712 signature verification failed
409CODE_ALREADY_EXISTSUser has already created a referral code
500DB_ERRORServer 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())

# Build EIP-712 typed data
typed_data = {
"types": {
"EIP712Domain": [
{"name": "name", "type": "string"},
{"name": "version", "type": "string"},
{"name": "chainId", "type": "uint256"},
],
"CreateReferralCode": [
{"name": "wallet", "type": "address"},
{"name": "timestamp", "type": "uint256"},
],
},
"primaryType": "CreateReferralCode",
"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/codes",
headers={"Authorization": f"Bearer {JWT_TOKEN}", "Content-Type": "application/json"},
json={"signature": signed.signature.hex(), "timestamp": timestamp},
)
print(resp.json())
# {"success": true, "code": "4DDDC2D4", "created_at": 1772010604000}