Skip to main content

Create Referral Code

Generate the account's unique 8-character referral code (uppercase hex, e.g. 4DDDC2D4). One code per account; it cannot be changed or deleted.

POST /referral/codes
Content-Type: application/json

Auth: Authorization: Bearer <JWT> from the EIP-712 login. API keys are not accepted.

Request body

{ "signature": "0x...", "timestamp": 1772010600 }
FieldTypeRequiredDescription
signaturestringyesEIP-712 signature (below)
timestampuint64yesUnix seconds, ±5 min

EIP-712 message

{
"primaryType": "CreateReferralCode",
"types": {
"CreateReferralCode": [
{ "name": "wallet", "type": "address" },
{ "name": "timestamp", "type": "uint256" }
]
},
"domain": "<typed_data.domain from GET /auth/nonce/{address}>",
"message": { "wallet": "0x<your_address>", "timestamp": 1772010600 }
}

The signature is verified: the recovered signer must equal the JWT's wallet address, and timestamp (seconds) must be within ±5 minutes.

Response

{ "success": true, "code": "4DDDC2D4", "created_at": 1772010604000 }

Errors

HTTPcode
400TIMESTAMP_EXPIRED, INVALID_SIGNATURE_FORMAT
401SIGNATURE_INVALID
409CODE_ALREADY_EXISTS
500DB_ERROR, CREATE_FAILED

Python

import time, requests
from eth_account import Account
from eth_account.messages import encode_typed_data

BASE = "https://api-avax.sparkydex.app/api/v1"
acct = Account.from_key("0xYourPrivateKey"); addr = acct.address.lower()
domain = requests.get(f"{BASE}/auth/nonce/{addr}").json()["typed_data"]["domain"]

ts = int(time.time())
typed = {
"types": {
"EIP712Domain": [
{"name": "name", "type": "string"}, {"name": "version", "type": "string"},
{"name": "chainId", "type": "uint256"}, {"name": "verifyingContract", "type": "address"},
],
"CreateReferralCode": [{"name": "wallet", "type": "address"}, {"name": "timestamp", "type": "uint256"}],
},
"primaryType": "CreateReferralCode",
"domain": domain,
"message": {"wallet": addr, "timestamp": ts},
}
sig = "0x" + acct.sign_message(encode_typed_data(full_message=typed)).signature.hex().removeprefix("0x")
r = requests.post(f"{BASE}/referral/codes", json={"signature": sig, "timestamp": ts},
headers={"Authorization": f"Bearer {JWT_TOKEN}"})
print(r.json())