JSPM

  • Created
  • Published
  • Downloads 2970
  • Score
    100M100P100Q122536F
  • License MIT

TypeScript SDK for Gala Launchpad Backend API - Production-ready DeFi token launchpad integration with wallet-based authentication, GalaChain trading, and comprehensive user operations. 100% tested (22/22 endpoints working).

Package Exports

  • @gala-chain/launchpad-sdk

Readme

Gala Launchpad SDK v0.4.0

A comprehensive TypeScript SDK for the Gala Launchpad Backend API, providing type-safe authentication, trading, and real-time features for DeFi applications.

npm version License: MIT TypeScript

๐Ÿš€ Features

Wallet Creation with Auto-Detection:

  • Auto-Detection: Automatically detects private key vs mnemonic input format
  • Flexible Input: Supports 12/24-word mnemonics and 64-character hex private keys
  • SDK Factory Functions: Simplified SDK initialization with createLaunchpadSDK()
  • Input Validation: Built-in validateWalletInput() for format validation
  • Test Support: createTestLaunchpadSDK() for testing environments
  • Flat API Design: All methods directly on SDK root for simplicity

Developer Experience

import { createLaunchpadSDK, createWallet } from '@gala-chain/launchpad-sdk';

// Auto-detect wallet format and create SDK
const sdk = createLaunchpadSDK({
  wallet: 'your-private-key-or-mnemonic' // Auto-detects format!
});

// Or create wallet separately with auto-detection
const wallet = createWallet('private-key-or-mnemonic');
const sdk = createLaunchpadSDK({ wallet });

// Test SDK with defaults
const testSDK = createTestLaunchpadSDK();

๐Ÿ“Š Flat API Architecture

All methods directly on SDK root - simple and clean:

// Everything is directly on sdk!
await sdk.fetchPools({ type: 'recent' });
await sdk.calculateBuyAmount({ tokenName: 'token', amount: '100', type: 'native' });
await sdk.buy({ tokenName: 'token', amount: '100', type: 'native' });
await sdk.fetchGalaBalance();
await sdk.postComment({ tokenName: 'token', content: 'Great project!' });

๐Ÿš€ Key Features

  • Type-Safe API Client: Full TypeScript support with comprehensive type definitions
  • Signature Authentication: Ethereum wallet-based authentication with automatic signature generation
  • Helper Functions: Auto-detecting wallet creation and SDK factory functions
  • Flat API Design: All methods directly accessible on SDK root
  • Pool Management: Create, fetch, and check token pools on the launchpad
  • Token Trading: Buy and sell tokens with slippage protection via GalaChain
  • User Operations: Portfolio management, token balances, and account management
  • Comment System: Post and retrieve comments on token pools
  • Comprehensive Validation: Input validation and error handling for all operations
  • Multi-Environment Support: Production, staging, and custom backend URLs

๐Ÿ“ฆ Installation

npm install @gala-chain/launchpad-sdk@^0.4.0

Or with yarn:

yarn add @gala-chain/launchpad-sdk@^0.4.0

๐Ÿ Quick Start

import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';

// Auto-detecting SDK creation (easiest method)
const sdk = createLaunchpadSDK({
  wallet: 'your-private-key-or-mnemonic' // Auto-detects format!
});

// Flat API - All methods directly on SDK root

// Pool Management
const pools = await sdk.fetchPools({ type: 'recent', limit: 10 });
const badges = await sdk.fetchTokenBadges('dragnrkti');
const details = await sdk.fetchSaleDetails('dragnrkti');

// Price Calculations
const buyAmount = await sdk.calculateBuyAmount({
  tokenName: 'dragnrkti',
  amount: '1000000000000000000', // 1 GALA
  type: 'native'
});

// Trading Operations
const buyResult = await sdk.buy({
  tokenName: 'dragnrkti',
  amount: '1000000000000000000',
  type: 'native',
  slippage: 5
});

// Data & Analytics
const trades = await sdk.fetchTrades({ tokenName: 'dragnrkti' });
const comments = await sdk.fetchComments({ tokenName: 'dragnrkti' });
const balance = await sdk.fetchGalaBalance();

// User Operations
const profile = await sdk.fetchProfile();
const tokenBalance = await sdk.fetchTokenBalance({
  tokenName: 'dragnrkti',
  walletAddress: sdk.getAddress()
});

Manual SDK Creation (Alternative)

import { Wallet } from 'ethers';
import { LaunchpadSDK } from '@gala-chain/launchpad-sdk';

// Create wallet manually
const wallet = new Wallet(process.env.PRIVATE_KEY);

// Initialize SDK
const sdk = new LaunchpadSDK({
  wallet: wallet,
  baseUrl: 'https://lpad-backend-dev1.defi.gala.com',
  timeout: 30000,
  debug: false
});

// Same flat API available
const pools = await sdk.fetchPools({ type: 'recent' });

๐ŸŽฏ Complete Example: Trading Flow

import { createLaunchpadSDK } from '@gala-chain/launchpad-sdk';

// 1. Create SDK with auto-detection
const sdk = createLaunchpadSDK({
  wallet: 'your-private-key-or-mnemonic'
});

// 2. Check available pools
const pools = await sdk.fetchPools({
  type: 'recent',
  limit: 10
});

// 3. Get price quote
const quote = await sdk.calculateBuyAmount({
  tokenName: 'tinyevil',
  amount: '100',
  type: 'native'
});

console.log(`Buying 100 GALA worth of tokens will get you: ${quote.outTokenAmount} TINYEVIL`);

// 4. Execute trade with slippage protection
const buyResult = await sdk.buy({
  tokenName: 'tinyevil',
  amount: '100',
  type: 'native',
  slippage: 5 // 5% slippage tolerance
});

// 5. Check trade history
const trades = await sdk.fetchTrades({ tokenName: 'tinyevil' });

// 6. Post a comment about your trade
await sdk.postComment({
  tokenName: 'tinyevil',
  content: 'Just bought some tokens! Great project!'
});

// 7. Check your balance
const balance = await sdk.fetchGalaBalance();
const tokenBalance = await sdk.fetchTokenBalance({
  tokenName: 'tinyevil',
  walletAddress: sdk.getAddress()
});

console.log(`GALA Balance: ${balance.balance}`);
console.log(`TINYEVIL Balance: ${tokenBalance.balance}`);

๐ŸŽฏ Available Methods

Fetch Operations

  • fetchPools(options?) - Get pools (recent, popular, search)
  • fetchTokenDistribution(tokenName) - Token holder distribution
  • fetchTokenBadges(tokenName) - Volume and engagement badges
  • fetchSaleDetails(tokenName) - Token sale information
  • fetchGraphData(options) - Price chart data
  • fetchTrades(options) - Trade history
  • fetchGalaBalance(walletAddress?) - User GALA balance
  • fetchTokenBalance(options) - User token balance
  • fetchComments(options) - Token comments
  • fetchProfile(walletAddress?) - User profile

Calculate Operations

  • calculateBuyAmount(options) - Calculate GALA cost for tokens
  • calculateSellAmount(options) - Calculate GALA received from tokens
  • calculateInitialBuyAmount(options) - Pre-mint calculations

Trading Operations

  • buy(options) - Buy tokens with slippage protection
  • sell(options) - Sell tokens with slippage protection

Content Operations

  • postComment(options) - Post comment on token
  • createTokenAndPool(data) - Create new token sale
  • uploadTokenImage(options) - Upload token image
  • updateProfile(data) - Update user profile
  • uploadProfileImage(options) - Upload profile image

Validation & Utilities

  • isTokenNameAvailable(tokenName) - Check name availability
  • isTokenSymbolAvailable(symbol) - Check symbol availability
  • getAddress() - Get backend format address (eth|...)
  • getEthereumAddress() - Get Ethereum format address (0x...)
  • resolveVaultAddress(tokenName) - Get token vault address
  • cleanup() - Cleanup resources

๐Ÿ”ง Helper Functions

Wallet Creation

import { createWallet, validateWalletInput } from '@gala-chain/launchpad-sdk';

// Auto-detect format and create wallet
const wallet = createWallet('private-key-or-24-word-mnemonic');
const randomWallet = createWallet(); // Generate random wallet

// Validate input format without creating wallet
const isValid = validateWalletInput('0x1234...'); // boolean

SDK Factory Functions

import { createLaunchpadSDK, createTestLaunchpadSDK } from '@gala-chain/launchpad-sdk';

// Main factory with auto-detection
const sdk = createLaunchpadSDK({
  wallet: 'your-private-key-or-mnemonic',
  config: {
    baseUrl: 'https://lpad-backend-dev1.defi.gala.com',
    debug: true
  }
});

// Test-optimized SDK
const testSDK = createTestLaunchpadSDK({
  wallet: 'test-private-key'
});

๐Ÿ”ง Configuration

interface LaunchpadSDKConfig {
  wallet: Wallet;                    // ethers.js Wallet instance
  baseUrl?: string;                  // Backend URL (default: dev environment)
  galaChainBaseUrl?: string;         // GalaChain gateway URL
  bundleBaseUrl?: string;            // Bundle service URL
  webSocketUrl?: string;             // WebSocket URL for monitoring
  timeout?: number;                  // Request timeout (default: 30000ms)
  debug?: boolean;                   // Enable debug logging
  maxRetries?: number;               // Retry attempts (default: 3)
  retryDelay?: number;               // Retry delay (default: 1000ms)
}

๐Ÿงช Testing

# Run all tests
npm test

# Run integration tests (requires environment setup)
npm run test:integration

# Run type checking
npm run typecheck

# Run linting
npm run lint

๐Ÿ“š Documentation

๐Ÿš€ Environment URLs

  • Development: https://lpad-backend-dev1.defi.gala.com
  • Production: https://lpad-backend-prod1.defi.gala.com

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

Please read CONTRIBUTING.md for guidelines on contributing to this project.

๐Ÿ“ž Support


Built with โค๏ธ for the Gala ecosystem