Skip to content

Commit 0c9c23b

Browse files
committedSep 27, 2023
docs: added docs to getDefaultProvider; fixes search in Flatworm (#4254).
1 parent b27faa0 commit 0c9c23b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
 

‎src.ts/providers/default-provider.ts

+43
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,49 @@ function isWebSocketLike(value: any): value is WebSocketLike {
2525

2626
const Testnets = "goerli kovan sepolia classicKotti optimism-goerli arbitrum-goerli matic-mumbai bnbt".split(" ");
2727

28+
/**
29+
* Returns a default provider for %%network%%.
30+
*
31+
* If %%network%% is a [[WebSocketLike]] or string that begins with
32+
* ``"ws:"`` or ``"wss:"``, a [[WebSocketProvider]] is returned backed
33+
* by that WebSocket or URL.
34+
*
35+
* If %%network%% is a string that begins with ``"HTTP:"`` or ``"HTTPS:"``,
36+
* a [[JsonRpcProvider]] is returned connected to that URL.
37+
*
38+
* Otherwise, a default provider is created backed by well-known public
39+
* Web3 backends (such as [[link-infura]]) using community-provided API
40+
* keys.
41+
*
42+
* The %%options%% allows specifying custom API keys per backend (setting
43+
* an API key to ``"-"`` will omit that provider) and ``options.exclusive``
44+
* can be set to either a backend name or and array of backend names, which
45+
* will whitelist **only** those backends.
46+
*
47+
* Current backend strings supported are:
48+
* - ``"alchemy"``
49+
* - ``"ankr"``
50+
* - ``"cloudflare"``
51+
* - ``"etherscan"``
52+
* - ``"infura"``
53+
* - ``"publicPolygon"``
54+
* - ``"quicknode"``
55+
*
56+
* @example:
57+
* // Connect to a local Geth node
58+
* provider = getDefaultProvider("http://localhost:8545/");
59+
*
60+
* // Connect to Ethereum mainnet with any current and future
61+
* // third-party services available
62+
* provider = getDefaultProvider("mainnet");
63+
*
64+
* // Connect to Polygoin, but only allow Etherscan and
65+
* // INFURA and use "MY_API_KEY" in calls to Etherscan.
66+
* provider = getDefaultProvider("matic", {
67+
* etherscan: "MY_API_KEY",
68+
* exclusive: [ "etherscan", "infura" ]
69+
* });
70+
*/
2871
export function getDefaultProvider(network: string | Networkish | WebSocketLike, options?: any): AbstractProvider {
2972
if (options == null) { options = { }; }
3073

0 commit comments

Comments
 (0)
Please sign in to comment.