ethers.js/packages/providers/lib.esm/index.js

87 lines
3.5 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
import { Provider } from "@ethersproject/abstract-provider";
import { getNetwork } from "@ethersproject/networks";
2020-09-04 01:37:14 -04:00
import { BaseProvider, Resolver } from "./base-provider";
2020-10-07 20:10:50 -04:00
import { AlchemyProvider, AlchemyWebSocketProvider } from "./alchemy-provider";
2022-03-19 02:59:38 -04:00
import { AnkrProvider } from "./ankr-provider";
import { CloudflareProvider } from "./cloudflare-provider";
import { EtherscanProvider } from "./etherscan-provider";
import { FallbackProvider } from "./fallback-provider";
import { IpcProvider } from "./ipc-provider";
2020-10-07 20:10:50 -04:00
import { InfuraProvider, InfuraWebSocketProvider } from "./infura-provider";
import { JsonRpcProvider, JsonRpcSigner } from "./json-rpc-provider";
2021-04-17 22:41:09 -04:00
import { JsonRpcBatchProvider } from "./json-rpc-batch-provider";
import { NodesmithProvider } from "./nodesmith-provider";
2020-10-18 23:19:16 -04:00
import { PocketProvider } from "./pocket-provider";
2024-02-23 22:30:55 -05:00
import { QuickNodeProvider } from "./quicknode-provider";
2020-06-29 00:54:30 -04:00
import { StaticJsonRpcProvider, UrlJsonRpcProvider } from "./url-json-rpc-provider";
import { Web3Provider } from "./web3-provider";
2020-03-12 19:14:50 +01:00
import { WebSocketProvider } from "./websocket-provider";
2020-10-07 20:10:50 -04:00
import { Formatter, isCommunityResourcable, isCommunityResource, showThrottleMessage } from "./formatter";
2019-11-20 18:57:38 +09:00
import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);
////////////////////////
// Helper Functions
function getDefaultProvider(network, options) {
if (network == null) {
network = "homestead";
}
2020-06-29 00:54:30 -04:00
// If passed a URL, figure out the right type of provider based on the scheme
if (typeof (network) === "string") {
// @TODO: Add support for IpcProvider; maybe if it ends in ".ipc"?
// Handle http and ws (and their secure variants)
const match = network.match(/^(ws|http)s?:/i);
if (match) {
2022-05-20 19:13:03 -04:00
switch (match[1].toLowerCase()) {
2020-06-29 00:54:30 -04:00
case "http":
2022-05-20 19:13:03 -04:00
case "https":
2020-06-29 00:54:30 -04:00
return new JsonRpcProvider(network);
case "ws":
2022-05-20 19:13:03 -04:00
case "wss":
2020-06-29 00:54:30 -04:00
return new WebSocketProvider(network);
default:
logger.throwArgumentError("unsupported URL scheme", "network", network);
}
}
}
2019-11-20 18:57:38 +09:00
const n = getNetwork(network);
if (!n || !n._defaultProvider) {
logger.throwError("unsupported getDefaultProvider network", Logger.errors.NETWORK_ERROR, {
operation: "getDefaultProvider",
network: network
});
}
return n._defaultProvider({
FallbackProvider,
AlchemyProvider,
2022-03-19 02:59:38 -04:00
AnkrProvider,
2019-11-20 18:57:38 +09:00
CloudflareProvider,
EtherscanProvider,
InfuraProvider,
JsonRpcProvider,
NodesmithProvider,
2020-10-18 23:19:16 -04:00
PocketProvider,
2024-02-23 22:30:55 -05:00
QuickNodeProvider,
2019-11-20 18:57:38 +09:00
Web3Provider,
IpcProvider,
}, options);
}
////////////////////////
// Exports
export {
// Abstract Providers (or Abstract-ish)
2020-09-04 01:37:14 -04:00
Provider, BaseProvider, Resolver, UrlJsonRpcProvider,
///////////////////////
2021-10-16 02:29:27 -04:00
// Concrete Providers
2024-02-23 22:30:55 -05:00
FallbackProvider, AlchemyProvider, AlchemyWebSocketProvider, AnkrProvider, CloudflareProvider, EtherscanProvider, InfuraProvider, InfuraWebSocketProvider, JsonRpcProvider, JsonRpcBatchProvider, NodesmithProvider, PocketProvider, QuickNodeProvider, StaticJsonRpcProvider, Web3Provider, WebSocketProvider, IpcProvider,
///////////////////////
// Signer
JsonRpcSigner,
///////////////////////
// Functions
2020-10-07 20:10:50 -04:00
getDefaultProvider, getNetwork, isCommunityResource, isCommunityResourcable, showThrottleMessage,
///////////////////////
// Objects
Formatter };
2020-07-13 08:03:56 -04:00
//# sourceMappingURL=index.js.map