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
69 lines (68 loc) • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GlobalExplorer = void 0;
const Client_1 = require("../Client");
/**
* Explorer for the ChainGate global endpoints.
*
* Provides access to cross-network market data, real-time network information,
* and network logos — including networks that don't have dedicated `/evm` or
* `/utxo` endpoints.
*
* @example
* ```ts
* const global = cg.exploreGlobal();
*
* // Crypto prices and fiat exchange rates
* const markets = await global.getMarkets();
*
* // Real-time info for all supported networks
* const info = await global.getNetworksInfo();
*
* // Logo URL for any supported network
* const url = global.getNetworkLogoUrl('berachain');
* ```
*/
class GlobalExplorer {
constructor(client, baseUrl, apiKey, global) {
this.client = client;
this.baseUrl = baseUrl;
this.apiKey = apiKey;
this.global = global;
}
/**
* Returns cryptocurrency prices and fiat exchange rates for all supported
* networks.
*
* Results are served from a TTL cache (60 s) shared with the rest of the
* library, so repeated calls within the TTL window are essentially free.
*/
async getMarkets() {
return this.global.marketsCache.fetch();
}
/**
* Returns real-time information for all supported EVM networks, including
* many that don't have dedicated `/evm` endpoints (e.g. Mantle, Celo,
* Moonbeam, Berachain, etc.).
*
* Includes block times, gas usage, and fee predictions.
*/
async getNetworksInfo() {
const { data } = await (0, Client_1.getGlobalNetworksInfo)({
client: this.client,
throwOnError: true,
});
return data;
}
/**
* Returns the URL endpoint for the SVG logo of the given network.
*
* Accepts any network supported by the global logo endpoint, including
* networks without dedicated `/evm` or `/utxo` endpoints.
*/
getNetworkLogoUrl(network) {
const suffix = this.apiKey ? `?api_key=${encodeURIComponent(this.apiKey)}` : '';
return `${this.baseUrl}/global/logo/${network}${suffix}`;
}
}
exports.GlobalExplorer = GlobalExplorer;