UNPKG

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.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RpcUrls = void 0; exports.buildRpcUrl = buildRpcUrl; const BASE_URL = 'https://api.chaingate.dev'; /** * Provides pre-built JSON-RPC endpoint URLs for every network supported by the * ChainGate RPC proxy. * * Each property returns a fully-qualified URL ready to be used with any * JSON-RPC client (ethers, viem, bitcoinjs, etc.) or with * {@link ChainGate.networks.evmRpc | `cg.networks.evmRpc()`}. When a * ChainGate API key is configured, it is appended automatically. * * @example * ```ts * const cg = new ChainGate(); * * // Use directly * console.log(cg.rpcUrls.ethereum); * // → "https://api.chaingate.dev/rpc/ethereum" * * // Combine with evmRpc connector * const polygon = cg.networks.evmRpc({ * rpcUrl: cg.rpcUrls.polygon, * chainId: 137, * name: 'Polygon', * symbol: 'POL', * }); * ``` */ class RpcUrls { /** @internal */ constructor(apiKey) { this._apiKey = apiKey; this.bitcoin = buildRpcUrl('bitcoin', apiKey); this.bitcoinTestnet = buildRpcUrl('bitcointestnet', apiKey); this.bitcoincash = buildRpcUrl('bitcoincash', apiKey); this.litecoin = buildRpcUrl('litecoin', apiKey); this.dogecoin = buildRpcUrl('dogecoin', apiKey); this.ethereum = buildRpcUrl('ethereum', apiKey); this.sonic = buildRpcUrl('sonic', apiKey); this.polygon = buildRpcUrl('polygon', apiKey); this.arbitrum = buildRpcUrl('arbitrum', apiKey); this.avalanche = buildRpcUrl('avalanche', apiKey); this.bnb = buildRpcUrl('bnb', apiKey); this.base = buildRpcUrl('base', apiKey); } /** * Returns the RPC URL for any supported network by its identifier. * * @example * ```ts * const url = cg.rpcUrls.get('polygon'); * // → "https://api.chaingate.dev/rpc/polygon" * ``` */ get(network) { return buildRpcUrl(network, this._apiKey); } } exports.RpcUrls = RpcUrls; /** @internal */ function buildRpcUrl(network, apiKey) { return apiKey ? `${BASE_URL}/rpc/${network}?api_key=${encodeURIComponent(apiKey)}` : `${BASE_URL}/rpc/${network}`; }