chaingate
v1.1.1
Published
Multi-chain cryptocurrency SDK for TypeScript — unified API for Bitcoin, Ethereum, Litecoin, Dogecoin, Bitcoin Cash, Polygon, Arbitrum, and any EVM-compatible chain. Create wallets, query balances, send transactions, and manage tokens and NFTs across UTXO
Downloads
1,069,548
Maintainers
Keywords
Readme
Features
- 👛 Wallet management -- Create HD wallets from mnemonics, import from seed, xpriv, xpub, private key, WIF, or keystores
- ⛓️ Multi-chain -- Bitcoin, Litecoin, Dogecoin, Bitcoin Cash, Ethereum, and any EVM chain via RPC
- 📍 Address derivation -- BIP-44/84/86 with segwit, legacy, taproot, cashaddr, and EOA
- 🔍 Blockchain explorer -- Balances, transactions, UTXOs, blocks, fees, tokens, and NFT metadata
- 📤 Transactions -- Send coins, ERC-20 tokens, NFTs, and call smart contracts with suggested fees
- 🔒 Encryption -- AES-256-GCM wallet encryption with password protection
- ✍️ Message signing -- EIP-191 (EVM) and Bitcoin-standard signing and verification
- 💱 Fiat conversion -- Live conversion to 160+ currencies
- 👁️ View-only wallets -- Read-only access from xpub or public key
Install
npm install chaingateExamples
Send $20 in Bitcoin
import { ChainGate, importWallet } from 'chaingate';
const cg = new ChainGate({ apiKey: 'your-api-key' });
const wallet = importWallet({ phrase: 'abandon abandon abandon ...' });
const btc = cg.connect(cg.networks.bitcoin, wallet);
// Convert $20 USD to the equivalent BTC amount at current market rate
const amount = await cg.networks.bitcoin.amountFromCurrency('usd', 20);
const tx = await btc.transfer(amount, 'bc1qRecipient...');
// Review suggested fees and pick one
const fees = tx.recommendedFees();
console.log(fees.normal.estimatedFeeSat); // estimated fee in satoshis
console.log(fees.normal.enoughFunds); // true if balance covers amount + fee
tx.setFee(fees.high);
const broadcasted = await tx.signAndBroadcast();
console.log('txid:', broadcasted.transactionId);Token Balances (ERC-20, ERC-721, ERC-1155)
const eth = cg.connect(cg.networks.ethereum, wallet);
const tokens = await eth.addressTokenBalances();
for (const token of tokens) {
if (token.isNFT) {
// ERC-721 or ERC-1155
console.log(`${token.name} -- ${token.ownedTokens.length} NFTs`);
} else {
// ERC-20
console.log(`${token.base()} ${token.symbol}`); // e.g. "1500.50 USDC"
}
}Transaction History (EVM)
Full decoded history with token transfers, approvals, wraps, and more:
const eth = cg.connect(cg.networks.ethereum, wallet);
const history = await eth.addressHistory();
for (const tx of history.transactions) {
console.log(tx.txHash, new Date(tx.timestamp * 1000));
// Decoded actions relevant to your address
for (const action of tx.actions) {
// action.type: "transfer_in", "transfer_out", "mint", "burn", "wrap", "unwrap", ...
// action.token: { name, symbol, decimals, logoUrl }
// action.contract: contract address or "native" for ETH transfers
console.log(` ${action.type} on ${action.token.symbol ?? 'ETH'}`);
}
}Transaction History (UTXO)
const btc = cg.connect(cg.networks.bitcoin, wallet);
const history = await btc.addressHistory();
for (const tx of history.transactions) {
const usd = await tx.amount.toCurrency('usd');
console.log(`${tx.txid}: ${tx.amount.base()} BTC ($${usd})`);
}Create a Wallet and Check Balance
import { ChainGate, newWallet } from 'chaingate';
const cg = new ChainGate({ apiKey: 'your-api-key' });
const { phrase, wallet } = newWallet();
console.log('Mnemonic:', phrase);
const eth = cg.connect(cg.networks.ethereum, wallet);
const balance = await eth.addressBalance();
const usd = await balance.confirmed.toCurrency('usd');
console.log(`${balance.confirmed.base()} ${balance.confirmed.symbol} ($${usd})`);Import a Wallet
import { importWallet, createWalletFromString } from 'chaingate';
// From mnemonic
const wallet = importWallet({ phrase: 'abandon abandon abandon ...' });
// From private key
importWallet({ privateKey: '0x...' });
// From xpub (view-only)
importWallet({ xpub: 'xpub...' });
// Auto-detect any format
const wallet = createWalletFromString('xprv9s21ZrQH143K...');Send ERC-20 Tokens
const eth = cg.connect(cg.networks.ethereum, wallet);
const usdc = cg.networks.ethereum.amount('100', {
contractAddress: '0xA0b8...eB48',
decimals: 6,
symbol: 'USDC',
});
const tx = await eth.transferToken(usdc, '0xRecipient...');
await tx.signAndBroadcast();Send NFTs
// ERC-721
const tx = await eth.transferNft('0xNftContract...', '0xRecipient...', tokenId);
// ERC-1155 (with quantity)
const tx = await eth.transferErc1155('0xNftContract...', tokenId, 5, '0xRecipient...');Connect to Any EVM Chain
const bsc = cg.networks.evmRpc({
rpcUrl: 'https://bsc-dataseed.binance.org',
chainId: 56,
name: 'BNB Smart Chain',
symbol: 'BNB',
});
const conn = cg.connect(bsc, wallet);
const balance = await conn.addressBalance();Encrypt and Save a Wallet
await wallet.encrypt('my-password');
const data = wallet.serialize();
// Restore later
import { deserializeWallet } from 'chaingate';
const restored = deserializeWallet(data, async () => {
return prompt('Enter password:');
});Validate Addresses
cg.networks.bitcoin.isValidAddress('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4'); // true
cg.networks.ethereum.isValidAddress('0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B'); // true
cg.networks.bitcoincash.isValidAddress('bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a'); // true
cg.networks.bitcoin.isValidAddress('0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B'); // false
cg.networks.ethereum.isValidAddress('not-an-address'); // falseSign Messages
import { signEvmMessage, verifyEvmMessage } from 'chaingate';
// EVM (EIP-191)
const signature = signEvmMessage('Hello', privateKey);
const isValid = verifyEvmMessage('Hello', signature, address);Supported Networks
| Network | Address Types | | --------------- | ----------------------- | | Bitcoin | segwit, legacy, taproot | | Litecoin | segwit, legacy | | Dogecoin | legacy | | Bitcoin Cash | cashaddr, legacy | | Bitcoin Testnet | segwit, legacy, taproot | | Ethereum | EOA | | Any EVM via RPC | EOA |
RPC proxy URLs included for Ethereum, Polygon, Arbitrum, Avalanche, BNB Chain, Base, and Sonic.
