coinlib-sdk
v3.2.0
Published
A unified multi-cryptocurrency wallet, transaction and payments library supporting Bitcoin, Ethereum, Ripple, Stellar, ERC20, Solana, Litecoin, Bitcoin Cash, and Dogecoin
Maintainers
Readme
Coinlib SDK - Packages Directory
A unified multi-cryptocurrency wallet, swap, stake, deploy smart contract, transaction and payments library supporting Bitcoin, Ethereum, Ripple, Stellar, ERC20, Solana, Cardano, Litecoin, Bitcoin Cash, Zcash ,and Dogecoin.
📦 Package Overview
This directory contains the core packages that make up the Coinlib SDK. Each package is designed to be modular and can be used independently or together to create comprehensive cryptocurrency applications.
Core Packages
coinlib- Main Coinlib class and unified APIcoinlib-hd- HD Wallet implementation with multi-currency supportcoinlib-link- Blockchain connectivity and communicationcoinlib-link-types- TypeScript types for blockchain operationscoinlib-link-utils- Utilities for blockchain operationscoinlib-type-utils- General TypeScript utilitiescoinlib-utils- General utility functionscoinlib-utxo-lib- UTXO transaction handlingcoinlib-websocket- WebSocket client for real-time blockchain data
🚀 Quick Start
Installation
npm install coinlib-sdkBasic Usage
import { Coinlib } from "coinlib-sdk";
import type { CoinlibConfig } from "coinlib-sdk";
// Initialize with Bitcoin
const config: CoinlibConfig = {
coins: "BTC",
network: "mainnet",
seed: "your-mnemonic-phrase-here",
};
const coinlib = new Coinlib(config);
// Derive an address
const address = await coinlib.deriveAddress(0);
console.log("Bitcoin Address:", address);
// Get balance
const balance = await coinlib.getBalance(address);
console.log("Balance:", balance);
// Sign transaction
const transaction = await coinlib.signTransaction(privateKey, fromAddress, toAddress, amount, feeRate);📋 Package Details
coinlib
The main entry point providing the unified Coinlib API.
Key Features:
- Unified interface for all cryptocurrency operations
- HD wallet integration
- Transaction signing and broadcasting
- Balance checking and transaction history
- Multi-network support (mainnet/testnet)
Main Classes:
Coinlib- Primary class for all operations- Configuration interfaces and types
coinlib-hd
Hierarchical Deterministic (HD) wallet implementation supporting multiple cryptocurrencies.
Key Features:
- BIP32/BIP44/BIP49/BIP84/BIP86 derivation paths
- 50+ supported cryptocurrencies
- Mnemonic generation and validation (BIP39)
- Multi-network address generation
- Private key management
Supported Cryptocurrencies:
- Bitcoin Family: BTC, LTC, BCH, DOGE, ZEC, etc.
- Ethereum Family: ETH, ETC, BSC, POL, ARB, OP, BASE and ERC20
- Other: XRP, XLM, ADA, SOL
Usage Example:
import { HDWallet } from "coinlib-sdk/coinlib-hd";
const wallet = HDWallet.generate(12, "english");
const btcAccount = wallet.deriveAccount("BTC", "mainnet");
console.log("Address:", btcAccount.address);coinlib-link
Blockchain connectivity layer providing communication with various blockchain networks.
Key Features:
- Multiple blockchain protocol support
- WebSocket and REST API connections
- Worker-based architecture for performance
- Proxy support (SOCKS)
- Connection pooling and management
Supported Workers:
- Blockbook - Bitcoin-family blockchains
- Ripple - XRP Ledger
- Solana - Solana blockchain
- Blockfrost - Cardano blockchain
- Stellar - Stellar network
coinlib-link-types
TypeScript type definitions for blockchain operations.
Key Exports:
AccountInfo- Account information structureTransaction- Transaction data typesTokenInfo- Token metadataServerInfo- Blockchain server information- Network-specific types for each supported blockchain
coinlib-link-utils
Utility functions for blockchain-specific operations.
Key Features:
- Address validation and formatting
- Network parameter handling
- Protocol-specific utilities
- Data transformation helpers
coinlib-type-utils
General TypeScript utility types and functions.
Key Features:
- Array manipulation utilities
- Object type helpers
- Branded types for type safety
- Timeout and promise utilities
- Exhaustive type checking
coinlib-utils
General utility functions used across the SDK.
Key Features:
- String and number formatting
- Cryptographic utilities
- Caching and deferred execution
- Logging and debugging tools
- Buffer and hex utilities
Notable Utilities:
BigNumber- Precise decimal arithmeticcreateDeferred- Promise utilitiesgetMutex- Concurrency controlbigNumber- Cryptocurrency amount handling
coinlib-utxo-lib
UTXO (Unspent Transaction Output) handling for Bitcoin-family cryptocurrencies.
Key Features:
- Transaction building and signing
- UTXO selection algorithms
- Script handling
- SegWit and Taproot support
- Fee calculation
coinlib-websocket
WebSocket client implementation for real-time blockchain data.
Key Features:
- Real-time transaction monitoring
- Block notifications
- Connection management
- Automatic reconnection
- Message queuing
🔧 Configuration
Environment Setup
// Basic configuration
const config: CoinlibConfig = {
coins: "BTC", // Cryptocurrency to use
network: "mainnet", // 'mainnet' or 'testnet'
seed: "mnemonic...", // BIP39 mnemonic phrase
passphrase: "", // Optional passphrase
debug: false, // Enable debug logging
};
// With proxy support
const configWithProxy: CoinlibConfig = {
coins: "ETH",
network: "mainnet",
seed: "mnemonic...",
proxy: {
host: "proxy.example.com",
port: 9050,
type: 5, // SOCKS5
},
};Supported Networks
- Mainnet: Production networks with real cryptocurrency
- Testnet: Test networks for development and testing
📚 Examples
Multi-Currency Wallet
import { Coinlib } from "coinlib-sdk";
const coins = ["BTC", "ETH", "LTC", "XRP"];
for (const coin of coins) {
const config = {
coins: coin,
network: "mainnet",
seed: "your-mnemonic-here",
};
const payment = new Coinlib(config);
const address = await payment.deriveAddress(0);
const balance = await payment.getBalance(address);
console.log(`${coin}: ${address} (${balance})`);
}Transaction Signing
import { Coinlib } from "coinlib-sdk";
const coinlib = new Coinlib({
coins: "BTC",
network: "testnet",
seed: "your-mnemonic-here",
});
// Sign a transaction
const signedTx = await coinlib.signTransaction(
"privateKey",
"fromAddress",
"toAddress",
0.001, // amount
0.00001 // fee rate
);
// Broadcast the transaction
const txHash = await coinlib.broadcastTransaction(signedTx);
console.log("Transaction hash:", txHash);Token Swapping
import { Coinlib } from "coinlib-sdk";
const coinlib = new Coinlib({
coins: "USDT", // from token
network: "mainnet",
seed: "your-mnemonic-here",
});
// Swap USDT to ETH
const swapTx = await coinlib.swapTransaction(
"privateKey",
"fromAddress",
"ETH", // to token
"100" // amount in USDT
);
console.log("Swap transaction:", swapTx);Coins Staking
import { Coinlib } from "coinlib-sdk";
const coinlib = new Coinlib({
coins: "ADA",
network: "mainnet",
seed: "your-mnemonic-here",
});
// Stake ADA
const swapTx = await coinlib.stakeTransaction(
"privateKey",
"fromAddress",
"0.003" // fee in ADA
"19" // amount in ADA
);
console.log("Stake transaction:", swapTx);🔒 Security
Best Practices
- Never expose private keys in client-side code
- Use testnet for development and testing
- Validate all inputs before processing
- Store mnemonics securely - never in plain text
- Use hardware wallets for production applications
Mnemonic Security
import { validateMnemonic, generateMnemonic } from "coinlib-sdk/coinlib-hd";
// Generate secure mnemonic
const mnemonic = generateMnemonic(24, { language: "english" });
// Validate before use
const validation = validateMnemonic(mnemonic);
if (!validation.isValid) {
throw new Error(`Invalid mnemonic: ${validation.error}`);
}🌐 Supported Cryptocurrencies
| Symbol | Name | Network | Address Type | | ------ | ------------ | --------------- | ------------------------- | | BTC | Bitcoin | Mainnet/Testnet | P2PKH, P2SH, P2WPKH, P2TR | | ETH | Ethereum | Mainnet/Testnet | 0x... | | LTC | Litecoin | Mainnet/Testnet | L..., M..., ltc1... | | BCH | Bitcoin Cash | Mainnet/Testnet | 1..., 3..., bitcoincash: | | XRP | Ripple | Mainnet/Testnet | r... | | XLM | Stellar | Mainnet/Testnet | G... | | ADA | Cardano | Mainnet/Testnet | addr1... | | SOL | Solana | Mainnet/Testnet | Base58 | | DOGE | Dogecoin | Mainnet/Testnet | D..., 9..., A... | | ZEC | Zcash | Mainnet/Testnet | Z..., |
And many more...
📖 API Reference
Coinlib Class
class Coinlib {
constructor(config: CoinlibConfig);
// Wallet operations
generateMnemonic(wordCount: MnemonicWordCount = 12, language: MnemonicLanguage = "english"): string
validateMnemonic(seed: string): MnemonicValidationResult
// Address operations
deriveAddress(index: number): Promise<string>;
validateAddress(address: string): boolean;
// Balance operations
getBalance(address: string): Promise<string>;
getAccountUtxo(address: string): Promise<Utxo[]>;
// Transaction operations
signTransaction(privateKey: string, from: string, to: string, amount: number, feeRate: number): Promise<string>;
broadcastTransaction(txHex: string): Promise<string>;
transferTransaction(privateKey: string, fromAddress: string, toAddress: string, amount: number | string, feeRate?: number | string): Promise<string>;
swapTransaction(privateKey: string, fromAddress: string, toCoins: CoinShortcut, amount: number | string): Promise<any>;
stakeTransaction(
privateKey: string,
fromAddress: string,
feeRate: number | string,
amount?: number | string;
options?: {
// for cardano
stakePrivateKey?: string;
poolId?: string;
// for solana
validatorAddress?: string;
}
): Promise<any>;
// History operations
getTransactionHistory(address: string, options?: <AccountInfoParams>): Promise<Transaction[]>;
getTransactionDetails(txid: string): Promise<Transaction>;
// Connection management
connect(): Promise<void>;
disconnect(): Promise<void>;
}Configuration Interface
interface CoinlibConfig {
coins?: CoinShortcut; // Cryptocurrency symbol
network: NetworkType; // 'mainnet' or 'testnet'
seed?: string; // BIP39 mnemonic phrase
passphrase?: string; // Optional BIP39 passphrase
proxy?: SocksProxyAgentOptions; // SOCKS proxy configuration
debug?: boolean; // Enable debug logging
}🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run tests and linting
- Submit a pull request
Development Setup
# Clone the repository
git clone https://github.com/amirulnubitel/coinlib-sdk.git
cd coinlib-sdk
# Install PNPM Global
npm install -g pnpm
# Install dependencies
pnpm install
# Build the project
pnpm run build
# Run tests
pnpm test📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🆘 Support
- Documentation: GitHub Repository
- Issues: GitHub Issues
⚠️ Security Notice: This library handles private keys and sensitive cryptographic material. Always follow security best practices and never expose private keys or mnemonics in production environments.
