Skip to main content

CeloRefer SDK API Reference

Welcome to the CeloRefer SDK API documentation. This reference provides detailed information about all available methods, parameters, and return values for integrating CeloRefer into your dApp.

Overview

The CeloRefer SDK is a TypeScript library built on top of viem that provides easy access to all CeloRefer smart contract functionality. It offers type-safe interactions with the contracts and handles all the complexity of blockchain interactions behind a simple API.

Installation

npm install celorefer-sdk viem

Initialization

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

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

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

Error Handling

All SDK methods can throw errors. Common error types include:
  • InvalidAddressError: When an invalid Ethereum address is provided
  • UnauthorizedError: When a method is called by an unauthorized account
  • InsufficientFundsError: When there aren’t enough funds for a transaction
  • ValidationError: When input parameters don’t meet requirements
Always wrap SDK calls in try-catch blocks:
try {
  const txHash = await sdk.registerUser('REF123ABC');
  console.log('Transaction hash:', txHash);
} catch (error) {
  console.error('Registration failed:', error.message);
}

Core Modules

The SDK is organized into several core modules:

Advanced Features

Utilities