Skip to main content

Create Referral Code

Generate a unique 8-character referral code (uppercase hex) for the current user. Each user can only have one code: if a code already exists, this endpoint is idempotent and returns the existing code (HTTP 200) instead of creating a new one.

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

Request Body​

{
"signature": "0x...",
"timestamp": 1772010600
}
FieldTypeRequiredDescription
signaturestringNoEIP-712 signature — accepted for forward compatibility, not verified
timestampuint64NoUnix timestamp (seconds) — accepted for forward compatibility, not verified

The backend currently ignores the request body entirely (an empty body is accepted); the caller is identified solely by the session Bearer token.

EIP-712 Signature​

Not verified by the backend at present; retained for forward compatibility.

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
successboolAlways true on success
codestringThe user's 8-character referral code (newly generated or pre-existing)
created_atint64Creation timestamp of the code (milliseconds)

Error Codes​

Error format. Referral endpoints return errors as a plain-text body (text/plain) containing the message shown in the Message column, not a JSON object. A missing or invalid Authorization: Bearer session token returns 401 with missing bearer token / invalid session.

HTTPMessageDescription
401missing bearer token / invalid sessionMissing, expired or revoked session token
500(database error text)Server error (including failure to generate a unique code after 5 attempts)

There is no CODE_ALREADY_EXISTS error: an existing code is returned with HTTP 200.

Code Examples​

Python​

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

BASE_URL = "https://api.rocky.exchange"
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": "Rocky", "version": "1", "chainId": 43114},
"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}/v1/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}