Rainbow Token Launcher SDK

A TypeScript SDK for launching and interacting with Rainbow Super Tokens
Installation
npm install @rainbow-me/token-launcher
yarn add @rainbow-me/token-launcher
Features
- Launch Rainbow Super Tokens on supported networks
- Launch tokens and buy in a single transaction
- Get airdrop suggestions for token distributions
- Retrieve token information
- Built-in error handling with descriptive error codes
- Full TypeScript support
Usage
Configuring the SDK
import { TokenLauncher } from '@rainbow-me/token-launcher';
TokenLauncher.configure({
API_URL_DEV: 'https://dev-api.example.com',
API_KEY_DEV: 'your-dev-api-key',
API_URL_PROD: 'https://api.example.com',
API_KEY_PROD: 'your-production-api-key',
MODE: 'production',
});
Launching a Rainbow Super Token
import { TokenLauncher, LaunchTokenParams } from '@rainbow-me/token-launcher';
import { Wallet, JsonRpcProvider } from 'ethers';
const provider = new JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_KEY');
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider);
const launchParams: LaunchTokenParams = {
name: 'My Token',
symbol: 'MTK',
supply: '1000000000000000000000000',
wallet: wallet,
initialTick: 0,
logoUrl: 'https://example.com/logo.png',
description: 'My awesome token for my community',
links: {
twitter: 'https://twitter.com/mytoken',
website: 'https://mytoken.com',
},
};
try {
const result = await TokenLauncher.launchToken(launchParams);
console.log('Token launched successfully!');
console.log('Transaction:', result.transaction.hash);
console.log('Token Address:', result.tokenAddress);
console.log('Token URI:', result.tokenUri);
} catch (error) {
console.error('Failed to launch token:', error);
}
Launch Token and Buy in One Transaction
import { TokenLauncher, LaunchTokenAndBuyParams } from '@rainbow-me/token-launcher';
import { parseEther } from 'ethers/lib/utils';
const launchAndBuyParams: LaunchTokenAndBuyParams = {
name: 'My Token',
symbol: 'MTK',
supply: '1000000000000000000000000',
wallet: wallet,
initialTick: 0,
logoUrl: 'https://example.com/logo.png',
amountIn: parseEther('0.1').toString(),
transactionOptions: {
gasLimit: '3000000',
maxFeePerGas: '50000000000',
maxPriorityFeePerGas: '1500000000',
gasPrice: '30000000000',
},
};
try {
const result = await TokenLauncher.launchTokenAndBuy(launchAndBuyParams);
console.log('Token launched and bought successfully!');
console.log('Transaction:', result.transaction.hash);
} catch (error) {
console.error('Failed to launch and buy token:', error);
}
Getting the Initial Tick
import { TokenLauncher } from '@rainbow-me/token-launcher';
import { parseEther } from 'ethers/lib/utils';
const tokenPriceInETH = parseEther('0.0001');
const initialTick = TokenLauncher.getInitialTick(tokenPriceInETH);
Getting Airdrop Suggestions
import { TokenLauncher } from '@rainbow-me/token-launcher';
const address = '0x1234567890123456789012345678901234567890';
const suggestions = await TokenLauncher.getAirdropSuggestions(address);
console.log('Predefined cohorts:', suggestions.predefinedCohorts);
console.log('Personalized cohorts:', suggestions.personalizedCohorts);
Error Handling
The SDK provides typed error codes for better error handling:
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('You do not have enough funds to complete this transaction.');
} else if (error.code === TokenLauncherErrorCode.WALLET_CONNECTION_ERROR) {
console.error('Could not connect to wallet. Please check your connection.');
} else {
console.error('An unexpected error occurred:', error.message);
}
}
API Reference
Core Methods
TokenLauncher.configure(config)
: Configure the SDK with API endpoints and keys
TokenLauncher.launchToken(params)
: Launch a new Rainbow Super Token
TokenLauncher.launchTokenAndBuy(params)
: Launch a token and buy in a single transaction
TokenLauncher.getInitialTick(tokenPrice)
: Calculate the initial tick based on token price
TokenLauncher.getAirdropSuggestions(address)
: Get airdrop suggestions for an address
TokenLauncher.getRainbowSuperTokens()
: Get all Rainbow Super Tokens
TokenLauncher.getRainbowSuperTokenByUri(uri)
: Get a specific token by URI
Error Codes
The SDK provides the following error codes for better error handling:
API_REQUEST_FAILED
: Failed to make API request
API_RESPONSE_INVALID
: Received invalid API response
SUBMISSION_DETAILS_MISSING
: Missing submission details
TRANSACTION_FAILED
: Transaction failed
CONTRACT_INTERACTION_FAILED
: Failed to interact with contract
INSUFFICIENT_FUNDS
: Insufficient funds for transaction
GAS_ESTIMATION_FAILED
: Failed to estimate gas
INVALID_SALT
: Invalid salt for token deployment
INVALID_PARAMS
: Invalid parameters
MISSING_REQUIRED_PARAM
: Missing required parameter
WALLET_CONNECTION_ERROR
: Wallet connection error
UNKNOWN_ERROR
: Unknown error
License
This project is licensed under the GNU General Public License v3.0 (GPL-3.0).