chaingate
Version:
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
119 lines (118 loc) • 4.67 kB
TypeScript
import { Amount } from '../../utils/Amount';
import type { BaseValue, FiatCurrency } from '../../utils/Amount';
import type { MarketsResponse } from '../../Client';
import type { TTLCache } from '../../utils/TTLCache';
import type { Network, NetworkInfoInternal, UtxoNetworkParams, AddressType, AddressTypeConfig } from './types';
/**
* Describes a blockchain network supported by ChainGate.
*
* Each instance carries the full network metadata and exposes the network
* identifier via its {@link id} property.
*
* @example
* ```ts
* const cg = new ChainGate();
* const btc = cg.networks.bitcoin;
* console.log(btc.name); // 'Bitcoin'
* console.log(btc.symbol); // 'BTC'
*
* // Create an Amount for transfers
* const amount = btc.amount('0.001');
* ```
*/
export declare class NetworkDescriptor<TAddressType extends AddressType = AddressType> {
/** Network identifier used in API calls (e.g. `"bitcoin"`, `"ethereum"`). */
readonly id: Network;
readonly name: string;
readonly symbol: string;
readonly type: 'evm' | 'utxo';
readonly decimals: number;
readonly isTestnet: boolean;
readonly hasOwnToken: boolean;
readonly nativeToken: {
readonly symbol: string;
readonly name: string;
};
readonly chainId?: number;
readonly defaultAddressType: TAddressType;
readonly addressTypes: Partial<Record<TAddressType, AddressTypeConfig>>;
/**
* Full JSON-RPC endpoint URL for this network on the ChainGate RPC proxy.
* When a ChainGate API key is configured, it is appended automatically.
*
* @example
* ```ts
* console.log(cg.networks.ethereum.rpcUrl);
* // → "https://api.chaingate.dev/rpc/ethereum"
* ```
*/
readonly rpcUrl: string;
/** @internal */
readonly networkParams?: UtxoNetworkParams;
/** @internal */
private readonly marketsCache;
/** @internal */
constructor(id: Network, info: NetworkInfoInternal, marketsCache: TTLCache<MarketsResponse>, apiKey?: string);
/**
* Derives a blockchain address from a compressed public key.
*
* Each network subclass implements the appropriate derivation algorithm:
* - **UTXO** networks: segwit, legacy, or taproot.
* - **Bitcoin Cash**: CashAddr or legacy.
* - **EVM** networks: EIP-55 checksummed address.
*
* @param publicKey - Compressed (33-byte) public key.
* @param addressType - Address encoding to use. Defaults to the network's
* {@link defaultAddressType}.
* @returns The derived address string.
*/
publicKeyToAddress(publicKey: Uint8Array, addressType?: TAddressType): string;
/**
* Checks whether a string is a valid address for this network.
*
* Each network subclass implements the appropriate validation:
* - **UTXO** networks: base58check and bech32/bech32m decoding.
* - **Bitcoin Cash**: CashAddr and legacy Base58Check formats.
* - **EVM** networks: hex format and EIP-55 checksum.
*
* @param address - The address string to validate.
* @returns `true` if the address is valid for this network.
*/
isValidAddress(address: string): boolean;
/**
* Creates an {@link Amount} in base units of the native coin
* (e.g. `0.001` for 0.001 BTC, `0.1` for 0.1 ETH).
*
* Accepts `number`, `string`, `bigint`, or a {@link DecimalLike} instance
* (e.g. `decimal.js`) for precision-safe input:
* - `btc.amount(0.001)` — convenient shorthand.
* - `btc.amount('0.00000001')` — full decimal precision.
* - `btc.amount(1n)` — exact integer (1 whole coin).
* - `btc.amount(new Decimal('0.001'))` — from a `decimal.js` instance.
*
* @example
* ```ts
* const amount = cg.networks.bitcoin.amount('0.001');
* const tx = await btc.transfer(amount, 'bc1q...');
* ```
*/
amount(value: BaseValue): Amount;
/**
* Creates an {@link Amount} from a fiat currency value, converting it to the
* native coin at the current market rate.
*
* @param fiat - Fiat currency symbol, case-insensitive (e.g. `"usd"`, `"EUR"`).
* @param value - The fiat amount (e.g. `50` for $50). Accepts `number`, `string`, `bigint`, or {@link DecimalLike}.
*
* @example
* ```ts
* const amount = await cg.networks.ethereum.amountFromCurrency('usd', 50);
* const tx = await eth.transfer(amount, '0x...');
* ```
*/
amountFromCurrency(fiat: FiatCurrency, value: BaseValue): Promise<Amount>;
/** Returns the network identifier string. */
toString(): string;
/** @internal */
private nativeAmountData;
}