Skip to main content

User Management

Methods for registering users and retrieving user information.

create

Creates a new instance of the CeloRefer SDK.
static create(chain: Chain, walletClient: WalletClient): CeloReferSDK

Parameters

NameTypeDescription
chainChainThe Celo chain to connect to (e.g., celoAlfajores)
walletClientWalletClientViem wallet client with account

Returns

CeloReferSDK - New SDK instance.

Example

import { CeloReferSDK } from 'celorefer-sdk';
import { createWalletClient, http } from 'viem';
import { celoAlfajores } from 'viem/chains';

const walletClient = createWalletClient({
  chain: celoAlfajores,
  transport: http()
});

const sdk = CeloReferSDK.create(celoAlfajores, walletClient);

registerUser

Registers a new user in the CeloRefer system with a referral code.
async registerUser(referralCode: string): Promise<Hex>

Parameters

NameTypeDescription
referralCodestringReferral code of the referring user

Returns

Hex - Transaction hash of the registration.

Example

const txHash = await sdk.registerUser('REF123ABC');
console.log('Registration transaction hash:', txHash);

registerGenesisUser

Registers a new user as a genesis user (first user with a custom code).
async registerGenesisUser(customCode: string): Promise<Hex>

Parameters

NameTypeDescription
customCodestringCustom referral code for the genesis user

Returns

Hex - Transaction hash of the registration.

Example

const txHash = await sdk.registerGenesisUser('MYCODE');
console.log('Genesis registration transaction hash:', txHash);

getUserInfo

Retrieves detailed information about a user.
async getUserInfo(userAddress: Address): Promise<UserInfo>

Parameters

NameTypeDescription
userAddressAddressAddress of the user

Returns

UserInfo object containing user details.

Example

const userInfo = await sdk.getUserInfo('0x1234...');
console.log('Referral code:', userInfo.referralCode);
console.log('Referral count:', userInfo.referralCount);
console.log('Badge tier:', userInfo.badgeTier);

getUserStats

Gets statistics for a user.
async getUserStats(userAddress: Address): Promise<UserStats>

Parameters

NameTypeDescription
userAddressAddressAddress of the user

Returns

UserStats object containing user statistics.

Example

const stats = await sdk.getUserStats('0x1234...');
console.log('Total referrals:', stats.totalReferrals);
console.log('Total earnings:', stats.totalEarnings);

getBadgeTier

Gets the badge tier for a user.
async getBadgeTier(userAddress: Address): Promise<number>

Parameters

NameTypeDescription
userAddressAddressAddress of the user

Returns

number - Badge tier (0-3 for Bronze, Silver, Gold, Platinum).

Example

const tier = await sdk.getBadgeTier('0x1234...');
console.log('Badge tier:', tier);

getReferralCode

Gets the referral code for a user.
async getReferralCode(userAddress: Address): Promise<string>

Parameters

NameTypeDescription
userAddressAddressAddress of the user

Returns

string - Referral code for the user.

Example

const code = await sdk.getReferralCode('0x1234...');
console.log('Referral code:', code);
Generates a referral link for sharing.
generateReferralLink(referralCode: string): string

Parameters

NameTypeDescription
referralCodestringReferral code to include in the link

Returns

string - Complete referral link.

Example

const link = sdk.generateReferralLink('REF123ABC');
console.log('Referral link:', link);

getBadgeInfo

Gets information about a specific badge tier.
getBadgeInfo(tier: number): BadgeInfo

Parameters

NameTypeDescription
tiernumberBadge tier (0-3)

Returns

BadgeInfo object containing badge details.

Example

const badgeInfo = sdk.getBadgeInfo(2); // Gold badge
console.log('Badge name:', badgeInfo.name);
console.log('Level 1 rate:', badgeInfo.level1Rate);