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
}
| Field | Type | Required | Description |
|---|---|---|---|
signature | string | No | EIP-712 signature — accepted for forward compatibility, not verified |
timestamp | uint64 | No | Unix 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
}
| Field | Type | Description |
|---|---|---|
success | bool | Always true on success |
code | string | The user's 8-character referral code (newly generated or pre-existing) |
created_at | int64 | Creation 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 invalidAuthorization: Bearersession token returns401withmissing bearer token/invalid session.
| HTTP | Message | Description |
|---|---|---|
| 401 | missing bearer token / invalid session | Missing, 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_EXISTSerror: 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}