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
}
| Field | Type | Required | Description |
|---|---|---|---|
signature | string | Yes | EIP-712 signature |
timestamp | uint64 | Yes | Unix 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
}
| Field | Type | Description |
|---|---|---|
success | bool | Whether creation succeeded |
code | string | The generated 8-character referral code |
created_at | int64 | Creation timestamp (milliseconds) |
Error Codes
| HTTP | Code | Description |
|---|---|---|
| 400 | TIMESTAMP_EXPIRED | Timestamp exceeds 5-minute validity window |
| 400 | INVALID_SIGNATURE_FORMAT | Signature string format is invalid |
| 401 | SIGNATURE_INVALID | EIP-712 signature verification failed |
| 409 | CODE_ALREADY_EXISTS | User has already created a referral code |
| 500 | DB_ERROR | 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())
# 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}