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
140 lines (139 loc) • 5.27 kB
TypeScript
import type { MarketsResponse } from '../Client';
import { UtxoExplorer } from '../Explorer/UtxoExplorer';
import { EvmExplorer } from '../Explorer/EvmExplorer';
import { GlobalExplorer } from '../Explorer/GlobalExplorer';
import { EvmConnector } from '../Connector/EvmConnector/EvmConnector';
import { EvmRpcConnector } from '../Connector/EvmRpcConnector/EvmRpcConnector';
import { EvmRpcExplorer } from '../Connector/EvmRpcConnector/EvmRpcExplorer';
import { UtxoConnector } from '../Connector/UtxoConnector/UtxoConnector';
import { BchConnector } from '../Connector/UtxoConnector/BchConnector/BchConnector';
import { UtxoNetworkDescriptor, BchNetworkDescriptor, EvmNetworkDescriptor, EvmRpcNetworkDescriptor } from './networks';
import type { NetworkCollection } from './networks';
import type { Wallet } from '../Wallet/Wallet';
import { TTLCache } from '../utils/TTLCache';
import { UtxoLocalCache } from '../utils/UtxoLocalCache';
import { EvmNonceCache } from '../utils/EvmNonceCache';
import { RpcUrls } from './RpcUrls';
/** Shared state created by {@link ChainGate} and threaded into explorers/connectors. */
export interface ChainGateGlobal {
marketsCache: TTLCache<MarketsResponse>;
utxoCache: UtxoLocalCache;
evmNonceCache: EvmNonceCache;
}
/**
* Main client for the ChainGate blockchain API.
*
* Provides access to the ChainGate API for querying blockchain data
* across EVM and UTXO networks.
*
* The API key is optional — without one you get a small rate limit suitable
* for trying things out. Get a free API key at https://api.chaingate.dev for
* a higher quota.
*
* @example
* ```ts
* import { ChainGate } from 'chaingate';
*
* const cg = new ChainGate();
*
* const btc = cg.explore(cg.networks.bitcoin); // UtxoExplorer
* const eth = cg.explore(cg.networks.ethereum); // EvmExplorer
* const avax = cg.explore(cg.networks.avalanche); // EvmExplorer
* ```
*/
export declare class ChainGate {
private readonly client;
private readonly apiKey;
private readonly _networks;
private readonly _rpcUrls;
/** @internal Shared state passed to explorers and connectors. */
readonly global: ChainGateGlobal;
/**
* Returns a `UtxoExplorer` for the given UTXO network.
*/
explore(network: UtxoNetworkDescriptor): UtxoExplorer;
/**
* Returns an `EvmExplorer` for the given EVM network.
*/
explore(network: EvmNetworkDescriptor): EvmExplorer;
/**
* Returns an `EvmRpcExplorer` for a custom EVM RPC network.
*/
explore(network: EvmRpcNetworkDescriptor): EvmRpcExplorer;
/**
* Returns a {@link GlobalExplorer} for querying cross-network data such as
* market prices, fiat exchange rates, real-time network information, and
* network logos — including networks that don't have dedicated `/evm` or
* `/utxo` endpoints.
*
* @example
* ```ts
* const global = cg.exploreGlobal();
*
* const markets = await global.getMarkets();
* const info = await global.getNetworksInfo();
* const logoUrl = global.getNetworkLogoUrl('berachain');
* ```
*/
exploreGlobal(): GlobalExplorer;
/**
* Returns the collection of all supported networks.
*
* The returned object is iterable (like an array) **and** has named
* properties for direct access:
*
* ```ts
* // Direct access
* cg.networks.bitcoin // UtxoNetworkDescriptor
* cg.networks.ethereum // EvmNetworkDescriptor
*
* // Iteration
* for (const net of cg.networks) { ... }
* ```
*/
get networks(): NetworkCollection;
/**
* Pre-built JSON-RPC endpoint URLs for every network supported by the
* ChainGate RPC proxy, with the API key already appended.
*
* Useful for passing to external libraries (ethers, viem, etc.) or to
* {@link NetworkCollection.evmRpc | `cg.networks.evmRpc()`}.
*
* @example
* ```ts
* // Use with evmRpc connector
* const polygon = cg.networks.evmRpc({
* rpcUrl: cg.rpcUrls.polygon,
* chainId: 137,
* name: 'Polygon',
* symbol: 'POL',
* });
*
* // Or pass to any JSON-RPC library
* const provider = new ethers.JsonRpcProvider(cg.rpcUrls.ethereum);
* ```
*/
get rpcUrls(): RpcUrls;
/**
* Connects a wallet to a network, returning a connector with address derivation,
* balance queries, transaction broadcasting, and smart contract calls.
*
* @example
* ```ts
* const connector = cg.connect(cg.networks.ethereum, wallet);
* const address = await connector.getAddress();
* ```
*/
connect(network: BchNetworkDescriptor, wallet: Wallet): BchConnector;
connect(network: EvmNetworkDescriptor, wallet: Wallet): EvmConnector;
connect(network: EvmRpcNetworkDescriptor, wallet: Wallet): EvmRpcConnector;
connect(network: UtxoNetworkDescriptor, wallet: Wallet): UtxoConnector;
/**
* @param options - Optional configuration.
* @param options.apiKey - Your ChainGate API key. Omit to use the keyless
* tier (small rate limit). Get a free key at https://api.chaingate.dev.
*/
constructor({ apiKey }?: {
apiKey?: string;
});
}