Overview
The Referrals API allows users to check referral code information and claim new referral codes on the UniDex platform.
Request Body
Action to perform. Must be one of:
getCodeInfo: Get information about a referral code
claimCode: Generate calldata to claim a referral code
The referral code to check or claim
Required for claimCode action. Ethereum address of the user claiming the code
Response Fields
For getCodeInfo action
32-byte representation of the referral code
Address of the code owner, or “Code not claimed” if unclaimed
Whether the code has been claimed
For claimCode action
Encoded function call data for claiming the code
Address of the referral contract
The referral code being claimed
32-byte representation of the referral code
Example Usage
curl -X POST "https://unidexv4-api-production.up.railway.app/api/referrals" \
-H "Content-Type: application/json" \
-d '{
"action": "getCodeInfo",
"code": "MYREFERRALCODE"
}'
Claim Code
curl -X POST "https://unidexv4-api-production.up.railway.app/api/referrals" \
-H "Content-Type: application/json" \
-d '{
"action": "claimCode",
"code": "MYREFERRALCODE",
"userAddress": "0x1234567890123456789012345678901234567890"
}'
Example Responses
For getCodeInfo
{
"code": "MYREFERRALCODE",
"bytes32Code": "0x4d59524546455252414c434f44450000000000000000000000000000000000",
"owner": "0x1234567890123456789012345678901234567890",
"isClaimed": true
}
For unclaimed code
{
"code": "MYREFERRALCODE",
"bytes32Code": "0x4d59524546455252414c434f44450000000000000000000000000000000000",
"owner": "Code not claimed",
"isClaimed": false
}
For claimCode
{
"calldata": "0x4d59524546455252414c434f4445000000000000000000000000000000000000",
"contractAddress": "0xe3ca135782e4a17aFb31a63ee3b15351C891A1A2",
"code": "MYREFERRALCODE",
"bytes32Code": "0x4d59524546455252414c434f44450000000000000000000000000000000000"
}
Error Responses
The endpoint will return appropriate error messages for:
- Missing action (
{"error": "Missing action"})
- Missing code for getCodeInfo (
{"error": "Missing code"})
- Missing code or userAddress for claimCode (
{"error": "Missing code or userAddress"})
- Invalid userAddress (
{"error": "Invalid userAddress"})
- Already claimed referral code (
{"error": "Referral code is already claimed"})
Available options:
getCodeInfo,
claimCode
Required for claimCode action
32-byte representation of the code
Address of code owner or 'Code not claimed'
Whether the code has been claimed