<divclass="link title"><ahref="/v5/">Documentation</a></div><divclass="base show link depth-1"><ahref="/v5/getting-started/">Getting Started</a></div><divclass="base show link depth-1"><ahref="/v5/concepts/">Ethereum Basics</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/events/">Events</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/gas/">Gas</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/security/">Security</a></div><divclass="base ancestor show link depth-1"><ahref="/v5/api/">Application Programming Interface</a></div><divclass="show link depth-2"><ahref="/v5/api/contract/">Contract Interaction</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract/">Contract</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract-factory/">ContractFactory</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><divclass="show link depth-2"><ahref="/v5/api/signer/">Signers</a></div><divclass="ancestor show link depth-2"><ahref="/v5/api/providers/">Providers</a></div><divclass="show link depth-3"><ahref="/v5/api/providers/provider/">Provider</a></div><divclass="show link depth-3"><ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><divclass="show link depth-3"><ahref="/v5/api/providers/api-providers/">API Providers</a></div><divclass="myself ancestor ancestor show link depth-3"><ahref="/v5/api/providers/other/">Other Providers</a></div><divclass="show link depth-3"><ahref="/v5/api/providers/types/">Types</a></div><divclass="show link depth-2"><ahref="/v5/api/utils/">Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/abi/">Application Binary Interface</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/coder/">AbiCoder</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/formats/">ABI Formats</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/fragments/">Fragments</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/interface/">Interface</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/address/">Addresses</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/bignumber/">BigNumber</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/bytes/">Byte Manipulation</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/constants/">Constants</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/display-logic/">Display Logic and Input</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/encoding/">Encoding Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/fixednumber/">FixedNumber</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/hashing/">Hashing Algorithms</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/hdnode/">HD Wallet</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/logger/">Logging</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/properties/">Property Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/signing-key/">Signing Key</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/strings/">Strings</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/transactions/">Transactions</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/web/">Web Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/wordlists/">Wordlists</a></div><divclass="show link depth-2"><ahref="/v5/api/other/">Other Libraries</a></div><divclass="hide link depth-3"><ahref="/v5/api/other/assembly/">Assembly</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/api/">Utilities</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/ast/">Abstract Syntax Tree</a></div><divclass="hide link depth-3"><ahref="/v5/api/other/hardware/">Hardware Wallets</a></div><divclass="sho
<aname="FallbackProvider"></a><aname="other-providers--FallbackProvider"></a><h2class="show-anchors"><div>FallbackProvider<spanclass="inherits"> inherits <ahref="/v5/api/providers/provider/">Provider</a></span><divclass="anchors"><aclass="self"href="/v5/api/providers/other/#FallbackProvider"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/fallback-provider.ts#L384">source</a></div></div></h2><p>The <b>FallbackProvider</b> is the most advanced <ahref="/v5/api/providers/provider/">Provider</a> available in ethers.</p>
<p>It uses a quorum and connects to multiple <ahref="/v5/api/providers/provider/">Providers</a> as backends, each configured with a <i>priority</i> and a <i>weight</i> .</p>
<p>When a request is made, the request is dispatched to multiple backends, randomly choosen (higher prioirty backends are always selected first) and the results from each are compared against the others. Only once the quorum has been reached will that result be accepted and returned to the caller.</p>
<p>By default the quorum requires 50% (rounded up) of the backends to agree. The <i>weight</i> can be used to give a backend Provider more influence.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="modifier">new </span><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">providers</span><spanclass="symbol">.</span><spanclass="method">FallbackProvider</span><spanclass="symbol">(</span><spanclass="param">providers</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">quorum</span><spanclass="symbol">]</span><spanclass="symbol">)</span><divclass="anchors"></div></div><divclass="body"><p>Creates a new instance of a FallbackProvider connected to <i>providers</i>. If quorum is not specified, half of the total sum of the provider weights is used.</p>
<p>The <i>providers</i> can be either an array of <ahref="/v5/api/providers/provider/">Provider</a> or <ahref="/v5/api/providers/other/#FallbackProviderConfig">FallbackProviderConfig</a>. If a <ahref="/v5/api/providers/provider/">Provider</a> is provided, the defaults are a priority of 1 and a weight of 1.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">provider</span><spanclass="symbol">.</span><spanclass="method">providerConfigs</span><spanclass="arrow">⇒</span><spanclass="returns">Array<<ahref="/v5/api/providers/other/#FallbackProviderConfig">FallbackProviderConfig</a>></span><divclass="anchors"></div></div><divclass="body"><p>The list of Provider Configurations that describe the backends.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">provider</span><spanclass="symbol">.</span><spanclass="method">quorum</span><spanclass="arrow">⇒</span><spanclass="returns">number</span><divclass="anchors"></div></div><divclass="body"><p>The quorum the backend responses must agree upon before a result will be resolved. By default this is <i>half the sum of the weights</i>.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">fallbackProviderConfig</span><spanclass="symbol">.</span><spanclass="method">provider</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/providers/provider/">Provider</a></span><divclass="anchors"></div></div><divclass="body"><p>The provider for this configuration.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">fallbackProviderConfig</span><spanclass="symbol">.</span><spanclass="method">priority</span><spanclass="arrow">⇒</span><spanclass="returns">number</span><divclass="anchors"></div></div><divclass="body"><p>The priority used for the provider. Higher priorities are favoured over lower priorities. If multiple providers share the same prioirty, they are choosen at random.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">fallbackProviderConfig</span><spanclass="symbol">.</span><spanclass="method">stallTimeout</span><spanclass="arrow">⇒</span><spanclass="returns">number</span><divclass="anchors"></div></div><divclass="body"><p>The timeout (in ms) after which another <ahref="/v5/api/providers/provider/">Provider</a> will be attempted. This does not affect the current Provider; if it returns a result it is counted as part of the quorum.</p>
<p>Lower values will result in more network traffic, but may reduce the response time of requests.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">fallbackProviderConfig</span><spanclass="symbol">.</span><spanclass="method">weight</span><spanclass="arrow">⇒</span><spanclass="returns">number</span><divclass="anchors"></div></div><divclass="body"><p>The weight a response from this provider provides. This can be used if a given <ahref="/v5/api/providers/provider/">Provider</a> is more trusted, for example.</p>
</div></div><aname="IpcProvider"></a><aname="other-providers--IpcProvider"></a><h2class="show-anchors"><div>IpcProvider<spanclass="inherits"> inherits <ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></span><divclass="anchors"><aclass="self"href="/v5/api/providers/other/#IpcProvider"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/ipc-provider.ts#L15">source</a></div></div></h2><p>The <b>IpcProvider</b> allows the JSON-RPC API to be used over a local filename on the file system, exposed by Geth, Parity and other nodes.</p>
<p>This is only available in <i>node.js</i> (as it requires file system access, and may have additional complications due to file permissions. See any related notes on the documentation for the actual node implementation websites.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">ipcProvider</span><spanclass="symbol">.</span><spanclass="method">path</span><spanclass="arrow">⇒</span><spanclass="returns">string</span><divclass="anchors"></div></div><divclass="body"><p>The path this <ahref="/v5/api/providers/provider/">Provider</a> is connected to.</p>
</div></div><aname="UrlJsonRpcProvider"></a><aname="other-providers--UrlJsonRpcProvider"></a><h2class="show-anchors"><div>UrlJsonRpcProvider<spanclass="inherits"> inherits <ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></span><divclass="anchors"><aclass="self"href="/v5/api/providers/other/#UrlJsonRpcProvider"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/url-json-rpc-provider.ts#L49">source</a></div></div></h2><p>This class is intended to be sub-classed and not used directly. It simplifies creating a <ahref="/v5/api/providers/provider/">Provider</a> where a normal <ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a> would suffice, with a little extra effort needed to generate the JSON-RPC URL.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="modifier">new </span><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">providers</span><spanclass="symbol">.</span><spanclass="method">UrlJsonRpcProvider</span><spanclass="symbol">(</span><spanclass="symbol">[</span><spanclass="param">network</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">apiKey</span><spanclass="symbol">]</span><spanclass="symbol">]</span><spanclass="symbol">)</span><divclass="anchors"></div></div><divclass="body"><p>Sub-classes do not need to override this. Instead they should override the static method <codeclass="inline">getUrl</code> and optionally <codeclass="inline">getApiKey</code>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">urlJsonRpcProvider</span><spanclass="symbol">.</span><spanclass="method">apiKey</span><spanclass="arrow">⇒</span><spanclass="returns">any</span><divclass="anchors"></div></div><divclass="body"><p>The value of the apiKey that was returned from <codeclass="inline">InheritedClass.getApiKey</code>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">InheritingClass</span><spanclass="symbol">.</span><spanclass="method">getApiKey</span><spanclass="symbol">(</span><spanclass="param">apiKey</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">any</span><divclass="anchors"></div></div><divclass="body"><p>This function should examine the <i>apiKey</i> to ensure it is valid and return a (possible modified) value to use in <codeclass="inline">getUrl</code>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">InheritingClass</span><spanclass="symbol">.</span><spanclass="method">getUrl</span><spanclass="symbol">(</span><spanclass="param">network</span><spanclass="symbol">,</span><spanclass="param">apiKey</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string</span><divclass="anchors"></div></div><divclass="body"><p>The URL to use for the JsonRpcProvider instance.</p>
</div></div><aname="Web3Provider"></a><aname="other-providers--Web3Provider"></a><h2class="show-anchors"><div>Web3Provider<spanclass="inherits"> inherits <ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></span><divclass="anchors"><aclass="self"href="/v5/api/providers/other/#Web3Provider"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/web3-provider.ts#L77">source</a></div></div></h2><p>The Web3Provider is meant to ease moving from a <ahref="https://github.com/ethereum/web3.js">web3.js based</a> application to ethers by wraping an existing Web3-compatible (such as a <ahref="https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-http">Web3HttpProvider</a>, <ahref="https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-ipc">Web3IpcProvider</a> or <ahref="https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-ws">Web3WsProvider</a>) and exposing it as an ethers.js <ahref="/v5/api/providers/provider/">Provider</a> which can then be used with the rest of the library.</p>
<p>This may also be used to wrap a standard [EIP-1193 Provider](link-eip-1193].</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="modifier">new </span><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">providers</span><spanclass="symbol">.</span><spanclass="method">Web3Provider</span><spanclass="symbol">(</span><spanclass="param">externalProvider</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">network</span><spanclass="symbol">]</span><spanclass="symbol">)</span><divclass="anchors"></div></div><divclass="body"><p>Create a new <b>Web3Provider</b>, which wraps an <ahref="https://eips.ethereum.org/EIPS/eip-1193">EIP-1193 Provider</a> or Web3Provider-compatible Provider.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">web3Provider</span><spanclass="symbol">.</span><spanclass="method">provider</span><spanclass="arrow">⇒</span><spanclass="returns">Web3CompatibleProvider</span><divclass="anchors"></div></div><divclass="body"><p>The provider used to create this instance.</p>
</div></div><aname="Web3Provider--ExternalProvider"></a><aname="other-providers--Web3Provider--Web3Provider--ExternalProvider"></a><h3class="show-anchors"><div>ExternalProvider<divclass="anchors"><aclass="self"href="/v5/api/providers/other/#Web3Provider--ExternalProvider"></a></div></div></h3><p>An <b>ExternalProvider</b> can be either one for the above mentioned Web3 Providers (or otherwise compatible) or an <ahref="https://eips.ethereum.org/EIPS/eip-1193">EIP-1193</a> provider.</p>
<p>An ExternalProvider must offer one of the following signatures, and the first matching is used:</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">externalProvider</span><spanclass="symbol">.</span><spanclass="method">request</span><spanclass="symbol">(</span><spanclass="param">request</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">Promise< any ></span><divclass="anchors"></div></div><divclass="body"><p>This follows the <ahref="https://eips.ethereum.org/EIPS/eip-1193">EIP-1193</a> API signature.</p>
<p>The <i>request</i> should be a standard JSON-RPC payload, which should at a minimum specify the <codeclass="inline">method</code> and <codeclass="inline">params</code>.</p>
<p>The result should be the actual result, which differs from the Web3.js response, which is a wrapped JSON-RPC response.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">externalProvider</span><spanclass="symbol">.</span><spanclass="method">sendAsync</span><spanclass="symbol">(</span><spanclass="param">request</span><spanclass="symbol">,</span><spanclass="param">callback</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">void</span><divclass="anchors"></div></div><divclass="body"><p>This follows the <ahref="https://github.com/ethereum/web3.js/blob/1.x/packages/web3-providers-http/types/index.d.ts#L57">Web3.js Provider Signature</a>.</p>
<p>The <i>request</i> should be a standard JSON-RPC payload, which should at a minimum specify the <codeclass="inline">method</code> and <codeclass="inline">params</code>.</p>
<p>The <i>callback</i> should use the error-first calling semantics, so <codeclass="inline">(error, result)</code> where the result is a JSON-RPC wrapped result.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">externalProvider</span><spanclass="symbol">.</span><spanclass="method">send</span><spanclass="symbol">(</span><spanclass="param">request</span><spanclass="symbol">,</span><spanclass="param">callback</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">void</span><divclass="anchors"></div></div><divclass="body"><p>This is identical to <codeclass="inline">sendAsync</code>. Historically, this used a synchronous web request, but no current browsers support this, so its use this way was deprecated quite a long time ago</p>
</div></div><aname="WebSocketProvider"></a><aname="other-providers--WebSocketProvider"></a><h2class="show-anchors"><div>WebSocketProvider<spanclass="inherits"> inherits <ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></span><divclass="anchors"><aclass="self"href="/v5/api/providers/other/#WebSocketProvider"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/websocket-provider.ts#L47">source</a></div></div></h2><p>The <b>WebSocketProvider</b> connects to a JSON-RPC WebSocket-compatible backend which allows for a persistent connection, multiplexing requests and pub-sub events for a more immediate event dispatching.</p>
<p>The WebSocket API is newer, and if running your own infrastructure, note that WebSockets are much more intensive on your server resourses, as they must manage and maintain the state for each client. For this reason, many services may also charge additional fees for using their WebSocket endpoints.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="modifier">new </span><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">provider</span><spanclass="symbol">.</span><spanclass="method">WebSockerProvider</span><spanclass="symbol">(</span><spanclass="symbol">[</span><spanclass="param">url</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">network</span><spanclass="symbol">]</span><spanclass="symbol">]</span><spanclass="symbol">)</span><divclass="anchors"></div></div><divclass="body"><p>Returns a new <ahref="/v5/api/providers/other/#WebSocketProvider">WebSocketProvider</a> connected to <i>url</i> as the <i>network</i>.</p>
<p>If <i>url</i> is unspecified, the default <codeclass="inline">"ws://localhost:8546"</code> will be used. If <i>network</i> is unspecified, it will be queried from the network.</p>
<divclass="copyright">The content of this site is licensed under the <ahref="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Generated on July 5, 2020, 12:0am.</div>