UNPKG

@metamask/network-controller

Version:

Provides an interface to the currently selected network via a MetaMask-compatible provider object

60 lines 2.9 kB
import type { PollingBlockTrackerOptions } from "@metamask/eth-block-tracker"; import type { Logger } from "loglevel"; import type { NetworkClientId, NetworkControllerMessenger } from "./NetworkController.cjs"; import type { RpcServiceOptions } from "./rpc-service/rpc-service.cjs"; import type { BlockTracker, NetworkClientConfiguration, Provider } from "./types.cjs"; /** * Why the degraded event was emitted. */ export type DegradedEventType = 'slow_success' | 'retries_exhausted'; /** * The category of error that was retried until retries were exhausted. */ export type RetryReason = 'connection_failed' | 'response_not_json' | 'non_successful_http_status' | 'timed_out' | 'connection_reset' | 'unknown'; /** * Classifies the error that was being retried when retries were exhausted. * * @param error - The error from the last retry attempt. * @returns A classification string. */ export declare function classifyRetryReason(error: unknown): RetryReason; /** * The pair of provider / block tracker that can be used to interface with the * network and respond to new activity. */ export type NetworkClient = { configuration: NetworkClientConfiguration; provider: Provider; blockTracker: BlockTracker; destroy: () => void; }; /** * Create a JSON RPC network client for a specific network. * * @param args - The arguments. * @param args.id - The ID that will be assigned to the new network client in * the registry. * @param args.configuration - The network configuration. * @param args.getRpcServiceOptions - Factory for constructing RPC service * options. See {@link NetworkControllerOptions.getRpcServiceOptions}. * @param args.getBlockTrackerOptions - Factory for constructing block tracker * options. See {@link NetworkControllerOptions.getBlockTrackerOptions}. * @param args.messenger - The network controller messenger. * @param args.isRpcFailoverEnabled - Whether or not requests sent to the * primary RPC endpoint for this network should be automatically diverted to * provided failover endpoints if the primary is unavailable. This effectively * causes the `failoverRpcUrls` property of the network client configuration * to be honored or ignored. * @param args.logger - A `loglevel` logger. * @returns The network client. */ export declare function createNetworkClient({ id, configuration, getRpcServiceOptions, getBlockTrackerOptions, messenger, isRpcFailoverEnabled, logger, }: { id: NetworkClientId; configuration: NetworkClientConfiguration; getRpcServiceOptions: (rpcEndpointUrl: string) => Omit<RpcServiceOptions, 'failoverService' | 'endpointUrl'>; getBlockTrackerOptions: (rpcEndpointUrl: string) => Omit<PollingBlockTrackerOptions, 'provider'>; messenger: NetworkControllerMessenger; isRpcFailoverEnabled: boolean; logger?: Logger; }): NetworkClient; //# sourceMappingURL=create-network-client.d.cts.map