UNPKG

eip155-chains

Version:

Aggregate all eip155 chains from multiple sources in one place.

114 lines (104 loc) 5.33 kB
import { Chain } from 'eth-chains'; import { Provider, JsonRpcProvider } from '@ethersproject/providers'; declare const KeyNotFound: Error; declare const ViemChainInfoNotFound: Error; declare const ChainNotFound: Error; declare const RpcNotFound: Error; declare const InvalidProviderConfigType: Error; declare function buf2hex(buffer: ArrayBufferLike): string; declare const getRandomUint8Array: (length?: number) => Uint8Array; declare function getRandomString(): string; declare function sleep(delay: number): Promise<unknown>; declare function getRpcsByChainId(chainId: number, extraRpcs?: RpcList, healthyCheckEanbled?: boolean, apiKeys?: ApiKeys, filters?: Filters): Promise<RpcList>; declare function healthyCheck(rpcs: RpcList): Promise<RpcList>; declare function splitRpcsByProtocol(rpcs: RpcList): ClassifiedRpc; declare function fulfillRpcFeatures(rpcs: RpcList): void; declare function filterRpcListByFeatures(rpcs: RpcList, features?: Array<RpcFeature>): RpcList; declare function isValidRpcProtocol(rpc: string): boolean; interface ClassifiedRpc { http: RPC[]; https: RPC[]; ws: RPC[]; wss: RPC[]; } interface RPC { url: RpcUrl; latency?: number; features?: Array<RpcFeature>; } type RpcUrl = `http://${string}` | `https://${string}` | `ws://${string}` | `wss://${string}`; type RpcList = Array<RPC>; type RpcFeatureFree = 'free to use'; type RpcFeatureLoadBalance = 'load balance'; type RpcFeaturePrivacy = 'privacy'; type RpcFeatureMevProtection = 'MEV protection'; type RpcFeaturePhishingProtection = 'phishing protection'; type RpcFeatureSmartContractWhitelist = 'smart contract whitelist'; type RpcFeatureSmartContractMethodChecks = 'smart contract method checks'; type RpcFeature = RpcFeatureFree | RpcFeatureLoadBalance | RpcFeaturePrivacy | RpcFeatureMevProtection | RpcFeaturePhishingProtection | RpcFeatureSmartContractWhitelist | RpcFeatureSmartContractMethodChecks; interface RpcService { getRpcList: (chainId: number, apiKey?: string) => RpcList | Promise<RpcList>; hasRpc?(url: RpcUrl): boolean; getFeatures?(): Array<RpcFeature>; } declare const registeredRpcServices: Array<RpcService>; declare function registerRpcService(service: RpcService): void; interface ApiKeys { INFURA_API_KEY?: string; ALCHEMY_API_KEY?: string; ANKR_API_KEY?: string; } interface Filters { features?: Array<RpcFeature>; } declare const RPC_TIMEOUT = 5000; interface EIP155Chain extends Chain { rpcList: RpcList; classifiedRpc: ClassifiedRpc; } interface Options { apiKeys?: ApiKeys; healthyCheckEnabled?: true; filters?: Filters; } declare function getChainById(chainId: number, options?: Options): Promise<EIP155Chain>; declare function getChainMetadataById(chainId: number): Promise<Chain | undefined>; declare function getChainMetadataByIdByEthChains(chainId: number): Chain | undefined; declare function getChainMetadataByIdByLocalFile(chainId: number): Chain | undefined; declare function getChainMetadataByIdByChainIdNetwork(chainId: number): Promise<Chain | undefined>; type ProviderConfig = ProviderConfigFallback | ProviderConfigRace; interface ProviderConfigFallback { type: 'fallback'; quorum?: number; } interface ProviderConfigRace { type: 'race'; } type ProviderOptions = Options & ProviderConfig; declare function getEthersProvider(chainId: number, options?: ProviderOptions): Promise<[Provider, () => Promise<void>]>; declare function destroyEthersProvider(provider: Provider): Promise<void>; interface EIP1193Provider { request: (request: { method: string; params?: Array<any>; }) => Promise<any>; } declare class RacedEIP1193Provider implements EIP1193Provider { providers: Array<EIP1193Provider>; constructor(providers: Array<EIP1193Provider>); static fromEthersJronRpcProviders(providers: Array<JsonRpcProvider>): RacedEIP1193Provider; request(request: { method: string; params?: Array<any>; }): Promise<any>; } declare class EthersJsonRpcProviderEIP1193Adapter implements EIP1193Provider { provider: JsonRpcProvider; constructor(provider: JsonRpcProvider); request(request: { method: string; params?: Array<any>; }): Promise<any>; private send; } export { type ApiKeys, ChainNotFound, type ClassifiedRpc, type EIP1193Provider, type EIP155Chain, EthersJsonRpcProviderEIP1193Adapter, type Filters, InvalidProviderConfigType, KeyNotFound, type Options, type ProviderConfig, type ProviderConfigFallback, type ProviderConfigRace, type ProviderOptions, type RPC, RPC_TIMEOUT, RacedEIP1193Provider, type RpcFeature, type RpcFeatureFree, type RpcFeatureLoadBalance, type RpcFeatureMevProtection, type RpcFeaturePhishingProtection, type RpcFeaturePrivacy, type RpcFeatureSmartContractMethodChecks, type RpcFeatureSmartContractWhitelist, type RpcList, RpcNotFound, type RpcService, type RpcUrl, ViemChainInfoNotFound, buf2hex, destroyEthersProvider, filterRpcListByFeatures, fulfillRpcFeatures, getChainById, getChainMetadataById, getChainMetadataByIdByChainIdNetwork, getChainMetadataByIdByEthChains, getChainMetadataByIdByLocalFile, getEthersProvider, getRandomString, getRandomUint8Array, getRpcsByChainId, healthyCheck, isValidRpcProtocol, registerRpcService, registeredRpcServices, sleep, splitRpcsByProtocol };