ethers.js/docs/v5/api/providers/index.html

68 lines
17 KiB
HTML
Raw Normal View History

2020-06-10 06:56:58 +03:00
<!DOCTYPE html>
<html class="paged">
<head>
<title>Providers</title>
<link rel="stylesheet" type="text/css" href="/v5/static/style.css">
</head>
<body>
<div class="sidebar">
<div class="header">
2020-07-03 08:54:56 +03:00
<div class="logo"><a href="/v5/"><div class="image"></div><div class="name">ethers</div><div class="version">v5.0</div></a></div>
2020-06-10 06:56:58 +03:00
</div>
<div class="toc"><div>
2020-09-08 08:12:15 +03:00
<div class="link title"><a href="/v5/">Documentation</a></div><div class="base show link depth-1"><a href="/v5/getting-started/">Getting Started</a></div><div class="base show link depth-1"><a href="/v5/concepts/">Ethereum Basics</a></div><div class="hide link depth-2"><a href="/v5/concepts/events/">Events</a></div><div class="hide link depth-2"><a href="/v5/concepts/gas/">Gas</a></div><div class="hide link depth-2"><a href="/v5/concepts/security/">Security</a></div><div class="base show link depth-1"><a href="/v5/api-keys/">Provider API Keys</a></div><div class="base ancestor show link depth-1"><a href="/v5/api/">Application Programming Interface</a></div><div class="myself ancestor ancestor show link depth-2"><a href="/v5/api/providers/">Providers</a></div><div class="child show link depth-3"><a href="/v5/api/providers/provider/">Provider</a></div><div class="child show link depth-3"><a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><div class="child show link depth-3"><a href="/v5/api/providers/api-providers/">API Providers</a></div><div class="child show link depth-3"><a href="/v5/api/providers/other/">Other Providers</a></div><div class="child show link depth-3"><a href="/v5/api/providers/types/">Types</a></div><div class="show link depth-2"><a href="/v5/api/signer/">Signers</a></div><div class="show link depth-2"><a href="/v5/api/contract/">Contract Interaction</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract/">Contract</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract-factory/">ContractFactory</a></div><div class="hide link depth-3"><a href="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><div class="show link depth-2"><a href="/v5/api/utils/">Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/abi/">Application Binary Interface</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/coder/">AbiCoder</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/formats/">ABI Formats</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/fragments/">Fragments</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/interface/">Interface</a></div><div class="hide link depth-3"><a href="/v5/api/utils/address/">Addresses</a></div><div class="hide link depth-3"><a href="/v5/api/utils/bignumber/">BigNumber</a></div><div class="hide link depth-3"><a href="/v5/api/utils/bytes/">Byte Manipulation</a></div><div class="hide link depth-3"><a href="/v5/api/utils/constants/">Constants</a></div><div class="hide link depth-3"><a href="/v5/api/utils/display-logic/">Display Logic and Input</a></div><div class="hide link depth-3"><a href="/v5/api/utils/encoding/">Encoding Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/fixednumber/">FixedNumber</a></div><div class="hide link depth-3"><a href="/v5/api/utils/hashing/">Hashing Algorithms</a></div><div class="hide link depth-3"><a href="/v5/api/utils/hdnode/">HD Wallet</a></div><div class="hide link depth-3"><a href="/v5/api/utils/logger/">Logging</a></div><div class="hide link depth-3"><a href="/v5/api/utils/properties/">Property Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/signing-key/">Signing Key</a></div><div class="hide link depth-3"><a href="/v5/api/utils/strings/">Strings</a></div><div class="hide link depth-3"><a href="/v5/api/utils/transactions/">Transactions</a></div><div class="hide link depth-3"><a href="/v5/api/utils/web/">Web Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/wordlists/">Wordlists</a></div><div class="show link depth-2"><a href="/v5/api/other/">Other Libraries</a></div><div class="hide link depth-3"><a href="/v5/api/other/assembly/">Assembly</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/api/">Utilities</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/ast/">Abstract Syntax Tree</a></di
2020-06-10 06:56:58 +03:00
</div></div>
</div>
<div class="content">
<div class="breadcrumbs"><a href="/v5/">Documentation</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="/v5/api/">API</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<span class="current">Providers</span></div>
<a name="providers"></a><a name="providers"></a><h1 class="show-anchors"><div>Providers<div class="anchors"><a class="self" href="/v5/api/providers/#providers"></a></div></div></h1><p>A <b>Provider</b> is an abstraction of a connection to the Ethereum network, providing a concise, consistent interface to standard Ethereum node functionality.</p>
<p>The ethers.js library provides several options which should cover the vast majority of use-cases, but also includes the necessary functions and classes for sub-classing if a more custom configuration is necessary.</p>
2020-09-08 08:12:15 +03:00
<p>Most users should use the <a href="/v5/api/providers/#providers-getDefaultProvider">Default Provider</a>.</p>
2020-06-10 06:56:58 +03:00
<a name="providers-getDefaultProvider"></a><a name="providers--providers-getDefaultProvider"></a><h2 class="show-anchors"><div>Default Provider<div class="anchors"><a class="self" href="/v5/api/providers/#providers-getDefaultProvider"></a></div></div></h2><p>The default provider is the safest, easiest way to begin developing on <i>Ethereum</i>, and it is also robust enough for use in production.</p>
<p>It creates a <a href="/v5/api/providers/other/#FallbackProvider">FallbackProvider</a> connected to as many backend services as possible. When a request is made, it is sent to multiple backends simulatenously. As responses from each backend are returned, they are checked that they agree. Once a quorum has been reached (i.e. enough of the backends agree), the response is provided to your application.</p>
<p>This ensures that if a backend has become out-of-sync, or if it has been compromised that its responses are dropped in favor of responses that match the majority.</p>
<div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="method">getDefaultProvider</span><span class="symbol">(</span> <span class="symbol">[</span> <span class="param">network</span> <span class="symbol">,</span> <span class="symbol">[</span> <span class="param">options</span> <span class="symbol">]</span> <span class="symbol">]</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/providers/provider/">Provider</a></span><div class="anchors"></div></div><div class="body"><p>Returns a new Provider, backed by multiple services, connected to <i>network</i>. Is no <i>network</i> is provided, <b>homestead</b> (i.e. mainnet) is used.</p>
2020-09-08 08:12:15 +03:00
<p>The <i>network</i> may also be a URL to connect to, such as <code class="inline">http://localhost:8545</code> or <code class="inline">wss://example.com</code>.</p>
2020-06-10 06:56:58 +03:00
<p>The <i>options</i> is an object, with the following properties:</p>
</div></div><table class="table minimal"><tr><td align="center"><b>Property</b></td><td align="center"><b>Description</b></td><td class="fix">&nbsp;</td></tr><tr><td align="center"><i>alchemy</i></td><td align="left"><a href="https://alchemyapi.io">Alchemy</a> API Token</td><td class="fix">&nbsp;</td></tr><tr><td align="center"><i>etherscan</i></td><td align="left"><a href="https://etherscan.io">Etherscan</a> API Token</td><td class="fix">&nbsp;</td></tr><tr><td align="center"><i>infura</i></td><td align="left"><a href="https://infura.io">INFURA</a> Project ID or ProjectID and Project Secret</td><td class="fix">&nbsp;</td></tr><tr><td align="center"><i>quorum</i></td><td align="left">The number of backends that must agree <i>(default: 2 for mainnet, 1 for testnets)</i></td><td class="fix">&nbsp;</td></tr><tr><td class="table-title" colspan="2">Option Properties</td><td class="fix">&nbsp;</td></tr></table><div class="definition container-box note"><div class="term">Note: API Keys</div><div class="body"><p>It is highly recommended for production services that to acquire and specify an API Key for each sercice.</p>
2020-07-03 08:54:56 +03:00
<p>The default API Keys used by ethers are shared across all users, so services may throttle all services that are using the default API Keys during periods of load without realizing it.</p>
2020-06-10 06:56:58 +03:00
2020-07-03 08:54:56 +03:00
<p>Many services also have monitoring and usage metrics, which are only available if an API Key is specified. This allows tracking how many requests are being sent and which methods are being used the most.</p>
2020-06-10 06:56:58 +03:00
2020-07-03 08:54:56 +03:00
<p>Some services also provide additional paid features, which are only available when specifying an API Key.</p>
2020-06-10 06:56:58 +03:00
2020-09-08 08:12:15 +03:00
</div></div><a name="providers--networks"></a><h2 class="show-anchors"><div>Networks<div class="anchors"><a class="self" href="/v5/api/providers/#providers--networks"></a></div></div></h2><p>There are several official common Ethereum networks as well as custom networks and other compatible projects.</p>
<p>Any API that accept a <a href="/v5/api/providers/types/#providers-Networkish">Networkish</a> can be passed a common name (such as <code class="inline">"mainnet"</code> or <code class="inline">"ropsten"</code>) to use that network definition or may specify custom parameters.</p>
<a name="providers--networks--custom-ens-contract"></a><h3 class="show-anchors"><div>Custom ENS Contract<div class="anchors"><a class="self" href="/v5/api/providers/#providers--networks--custom-ens-contract"></a></div></div></h3><p>One common reason to specify custom properties for a <a href="/v5/api/providers/types/#providers-Network">Network</a> is to override the address of the root ENS registry, either on a common network to intercept the <a href="/v5/api/providers/provider/#Provider--ens-methods">ENS Methods</a> or to specify the ENS registry on a dev network (on most dev networks you must deploy the ENS contracts manually).</p>
<div class="code-title"><div>Example: Override the ENS registry</div></div><div class="code">const network = {
name: "dev",
chianId: 1337,
ensAddress: customEnsAddress
};
</div><a name="providers--provider-documentation"></a><h2 class="show-anchors"><div>Provider Documentation<div class="anchors"><a class="self" href="/v5/api/providers/#providers--provider-documentation"></a></div></div></h2>
<div class="toc"><div style="padding-left: 0px"><span class="bullet">&bull;</span><a href="/v5/api/providers/provider/">Provider</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/provider/#Provider--account-methods">Accounts Methods</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/provider/#Provider--block-methods">Blocks Methods</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/provider/#Provider--ens-methods">Ethereum Naming Service (ENS) Methods</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/provider/#Provider--log-methods">Logs Methods</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/provider/#Provider--network-methods">Network Status Methods</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/provider/#Provider--transaction-methods">Transactions Methods</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/provider/#Provider--event-methods">Event Emitter Methods</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/provider/#Provider--inspection-methods">Inspection Methods</a></div><div style="padding-left: 0px"><span class="bullet">&bull;</span><a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/jsonrpc-provider/#JsonRpcSigner">JsonRpcSigner</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/jsonrpc-provider/#UncheckedJsonRpcSigner">JsonRpcUncheckedSigner</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/jsonrpc-provider/#JsonRpcProvider--other">Node-Specific Methods</a></div><div style="padding-left: 0px"><span class="bullet">&bull;</span><a href="/v5/api/providers/api-providers/">API Providers</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/api-providers/#EtherscanProvider">EtherscanProvider</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/api-providers/#InfuraProvider">InfuraProvider</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/api-providers/#AlchemyProvider">AlchemyProvider</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/api-providers/#CloudflareProvider">CloudflareProvider</a></div><div style="padding-left: 0px"><span class="bullet">&bull;</span><a href="/v5/api/providers/other/">Other Providers</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/other/#FallbackProvider">FallbackProvider</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/other/#IpcProvider">IpcProvider</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/other/#UrlJsonRpcProvider">UrlJsonRpcProvider</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/other/#Web3Provider">Web3Provider</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/other/#WebSocketProvider">WebSocketProvider</a></div><div style="padding-left: 0px"><span class="bullet">&bull;</span><a href="/v5/api/providers/types/">Types</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/types/#providers-BlockTag">BlockTag</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/types/#providers-Networkish">Networkish</a></div><div style="padding-left: 28px"><span class="bullet">&bull;</span><a href="/v5/api/providers/type
2020-06-10 06:56:58 +03:00
<div class="footer">
2020-09-08 08:12:15 +03:00
<div class="nav previous"><a href="/v5/api/"><span class="arrow">&larr;</span>Application Programming Interface</a></div>
2020-06-10 06:56:58 +03:00
<div class="nav next"><a href="/v5/api/providers/provider/">Provider<span class="arrow">&rarr;</span></a></div>
</div>
2020-09-08 08:12:15 +03:00
<div class="copyright">The content of this site is licensed under the <a href="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Generated on September 8, 2020, 1:8am.</div>
2020-06-10 06:56:58 +03:00
</div>
<script src="/v5/static/script.js" type="text/javascript"></script>
</body>
</html>