This document provides detailed API documentation for the Rainbow Token Launcher SDK.
The main entry point to the SDK is the TokenLauncher singleton object, which provides access to all SDK functionality.
import { TokenLauncher } from '@rainbow-me/token-launcher';Configures the SDK with the necessary API endpoints, keys, and other settings.
Parameters:
interface SDKConfig {
// API URLs
API_URL_DEV?: string;
API_URL_PROD?: string;
// API keys
API_KEY_DEV?: string;
API_KEY_PROD?: string;
// Supported networks
SUPPORTED_NETWORKS?: SupportedNetwork[];
// Mode
MODE?: 'jest' | 'development' | 'production';
}
interface SupportedNetwork {
chainId: number;
contractAddress: string;
}Example:
TokenLauncher.configure({
API_URL_PROD: 'https://api.example.com',
API_KEY_PROD: 'your-api-key',
MODE: 'production',
SUPPORTED_NETWORKS: [
{
chainId: 1, // Ethereum Mainnet
contractAddress: '0x1234567890123456789012345678901234567890'
},
{
chainId: 137, // Polygon Mainnet
contractAddress: '0x0987654321098765432109876543210987654321'
}
]
});Returns the current SDK configuration.
Returns: SDKConfig - The current configuration object
Example:
const config = TokenLauncher.getConfig();
console.log('Current API URL:', config.MODE === 'production' ? config.API_URL_PROD : config.API_URL_DEV);Launches a new Rainbow Super Token.
Parameters:
interface LaunchTokenParams {
name: string; // Token name
symbol: string; // Token symbol
supply: string; // Total supply (in wei format)
wallet: Wallet; // Ethers.js Wallet instance
initialTick?: number; // Initial tick (price setting)
creator?: string; // Creator address (defaults to wallet address)
transactionOptions?: { // Optional gas parameters
gasLimit?: string;
gasPrice?: string; // For legacy transactions
maxFeePerGas?: string; // For EIP-1559 transactions
maxPriorityFeePerGas?: string; // For EIP-1559 transactions
};
logoUrl: string; // URL to token logo image
description?: string; // Token description
links?: Record<string, string>; // Social/website links
airdropMetadata?: AirdropMetadata; // Optional airdrop information
}Returns: Promise<LaunchTokenResponse> - A promise that resolves to the token launch response
interface LaunchTokenResponse {
transaction: TransactionResponse; // Ethers.js TransactionResponse
tokenUri: string; // Token URI
tokenAddress: string; // Deployed token contract address
}Example:
const result = await TokenLauncher.launchToken({
name: 'My Token',
symbol: 'MTK',
supply: '1000000000000000000000000', // 1 million tokens (with 18 decimals)
wallet: wallet,
initialTick: 0,
logoUrl: 'https://example.com/logo.png',
description: 'My awesome community token',
links: {
twitter: 'https://twitter.com/mytoken',
website: 'https://mytoken.com'
}
});Launches a new Rainbow Super Token and buys some tokens in a single transaction.
Parameters:
interface LaunchTokenAndBuyParams extends LaunchTokenParams {
amountIn: string; // Required: Amount of ETH to use for purchase (in wei format)
}Returns: Promise<LaunchTokenResponse> - Same as launchToken method
Example:
const result = await TokenLauncher.launchTokenAndBuy({
name: 'My Token',
symbol: 'MTK',
supply: '1000000000000000000000000',
wallet: wallet,
initialTick: 0,
logoUrl: 'https://example.com/logo.png',
amountIn: '100000000000000000', // 0.1 ETH
transactionOptions: {
gasLimit: '3000000',
gasPrice: '30000000000' // 30 gwei - for legacy networks
}
});Calculates the initial tick value based on the desired token price.
Parameters:
tokenPrice:BigNumber- The desired token price in ETH (as a BigNumber)
Returns: number - The calculated tick value
Example:
import { parseEther } from 'ethers/lib/utils';
// For a token price of 0.0001 ETH
const tokenPrice = parseEther('0.0001');
const tick = TokenLauncher.getInitialTick(tokenPrice);Gets a list of all Rainbow Super Tokens.
Returns: Promise<GetRainbowSuperTokensResponse> - A promise that resolves to the list of tokens
Example:
const tokens = await TokenLauncher.getRainbowSuperTokens();
console.log('Total tokens:', tokens.data.length);Gets information about a specific Rainbow Super Token by its URI.
Parameters:
uri:string- The token URI
Returns: Promise<GetRainbowSuperTokenResponse> - A promise that resolves to the token information
Example:
const tokenInfo = await TokenLauncher.getRainbowSuperTokenByUri('https://example.com/token/123');
console.log('Token name:', tokenInfo.data.name);Gets airdrop suggestions for a specific address.
Parameters:
address:string- The address to get suggestions for
Returns: Promise<GetAirdropSuggestionsResponse> - A promise that resolves to the airdrop suggestions
Example:
const suggestions = await TokenLauncher.getAirdropSuggestions('0x1234567890123456789012345678901234567890');
// Access predefined cohorts
console.log('Predefined cohorts:', suggestions.predefinedCohorts);
// Access personalized cohorts
console.log('Personalized cohorts:', suggestions.personalizedCohorts);The SDK provides typed error codes for better error handling. All errors thrown by the SDK will be instances of TokenLauncherSDKError.
class TokenLauncherSDKError extends Error {
readonly code: TokenLauncherErrorCode;
readonly context: {
operation: string;
params?: any;
source: 'api' | 'chain' | 'sdk';
chainId?: number;
transactionHash?: string;
originalError?: any;
};
}The following error codes are available:
API_REQUEST_FAILED: Failed to make API requestAPI_RESPONSE_INVALID: Received invalid API responseSUBMISSION_DETAILS_MISSING: Missing submission detailsTRANSACTION_FAILED: Transaction failedCONTRACT_INTERACTION_FAILED: Failed to interact with contractINSUFFICIENT_FUNDS: Insufficient funds for transactionGAS_ESTIMATION_FAILED: Failed to estimate gasINVALID_SALT: Invalid salt for token deploymentINVALID_PARAMS: Invalid parametersMISSING_REQUIRED_PARAM: Missing required parameterWALLET_CONNECTION_ERROR: Wallet connection errorUNKNOWN_ERROR: Unknown error
Example usage:
import { TokenLauncher, TokenLauncherErrorCode } from '@rainbow-me/token-launcher';
try {
const result = await TokenLauncher.launchToken(params);
} catch (error) {
if (error.code === TokenLauncherErrorCode.INSUFFICIENT_FUNDS) {
console.error('Insufficient funds for transaction. Please add more funds to your wallet.');
} else if (error.code === TokenLauncherErrorCode.CONTRACT_INTERACTION_FAILED) {
console.error('Failed to interact with contract:', error.message);
console.log('Operation that failed:', error.context.operation);
console.log('Source of error:', error.context.source);
} else {
console.error('Unknown error:', error);
}
}