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

114 lines
24 KiB
HTML
Raw Normal View History

2020-06-10 06:56:58 +03:00
<!DOCTYPE html>
<html class="paged">
<head>
<title>Other 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-11-23 07:07:13 +03:00
<div class="search"><form action="/v5/search/" method="GET"><input name="search" id="search" /></form><span class="search-icon">&#9906;</span></div>
2020-06-10 06:56:58 +03:00
</div>
<div class="toc"><div>
2020-11-23 07:07:13 +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="hide link depth-2"><a href="/v5/concepts/best-practices/">Best Practices</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="ancestor show link depth-2"><a href="/v5/api/providers/">Providers</a></div><div class="show link depth-3"><a href="/v5/api/providers/provider/">Provider</a></div><div class="show link depth-3"><a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><div class="show link depth-3"><a href="/v5/api/providers/api-providers/">API Providers</a></div><div class="myself ancestor ancestor show link depth-3"><a href="/v5/api/providers/other/">Other Providers</a></div><div class="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 de
2020-06-10 06:56:58 +03:00
</div></div>
2020-11-23 07:07:13 +03:00
<div class="footer">
<a href="/v5/single-page/">Single Page</a>
</div>
2020-06-10 06:56:58 +03:00
</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;<a href="/v5/api/providers/">Providers</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<span class="current">Other Providers</span></div>
<a name="other-providers"></a><h1 class="show-anchors"><div>Other Providers<div class="anchors"><a class="self" href="/v5/api/providers/other/#other-providers"></a></div></div></h1><p>Others...</p>
2020-11-23 07:07:13 +03:00
<a name="FallbackProvider"></a><a name="other-providers--FallbackProvider"></a><h2 class="show-anchors"><div>FallbackProvider<span class="inherits"> inherits <a href="/v5/api/providers/provider/">Provider</a></span><div class="anchors"><a class="self" href="/v5/api/providers/other/#FallbackProvider"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/fallback-provider.ts#L403">source</a></div></div></h2><p>The <b>FallbackProvider</b> is the most advanced <a href="/v5/api/providers/provider/">Provider</a> available in ethers.</p>
2020-06-10 06:56:58 +03:00
<p>It uses a quorum and connects to multiple <a href="/v5/api/providers/provider/">Providers</a> as backends, each configured with a <i>priority</i> and a <i>weight</i> .</p>
2020-11-23 07:07:13 +03:00
<p>When a request is made, the request is dispatched to multiple backends, randomly chosen (higher priority 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>
2020-06-10 06:56:58 +03:00
<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>
<div class="property show-anchors"><div class="signature"><span class="modifier">new </span><span class="path">ethers</span><span class="symbol">.</span><span class="path">providers</span><span class="symbol">.</span><span class="method">FallbackProvider</span><span class="symbol">(</span> <span class="param">providers</span> <span class="symbol">[</span> <span class="symbol">,</span> <span class="param">quorum</span> <span class="symbol">]</span> <span class="symbol">)</span><div class="anchors"></div></div><div class="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 <a href="/v5/api/providers/provider/">Provider</a> or <a href="/v5/api/providers/other/#FallbackProviderConfig">FallbackProviderConfig</a>. If a <a href="/v5/api/providers/provider/">Provider</a> is provided, the defaults are a priority of 1 and a weight of 1.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">provider</span><span class="symbol">.</span><span class="method">providerConfigs</span> <span class="arrow">&rArr;</span> <span class="returns">Array&lt; <a href="/v5/api/providers/other/#FallbackProviderConfig">FallbackProviderConfig</a> &gt;</span><div class="anchors"></div></div><div class="body"><p>The list of Provider Configurations that describe the backends.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">provider</span><span class="symbol">.</span><span class="method">quorum</span> <span class="arrow">&rArr;</span> <span class="returns">number</span><div class="anchors"></div></div><div class="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>
</div></div><a name="FallbackProviderConfig"></a><a name="other-providers--FallbackProvider--FallbackProviderConfig"></a><h3 class="show-anchors"><div>FallbackProviderConfig<div class="anchors"><a class="self" href="/v5/api/providers/other/#FallbackProviderConfig"></a></div></div></h3>
<div class="property show-anchors"><div class="signature"><span class="path">fallbackProviderConfig</span><span class="symbol">.</span><span class="method">provider</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>The provider for this configuration.</p>
2020-11-23 07:07:13 +03:00
</div></div><div class="property show-anchors"><div class="signature"><span class="path">fallbackProviderConfig</span><span class="symbol">.</span><span class="method">priority</span> <span class="arrow">&rArr;</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The priority used for the provider. Higher priorities are favoured over lower priorities. If multiple providers share the same priority, they are chosen at random.</p>
2020-06-10 06:56:58 +03:00
</div></div><div class="property show-anchors"><div class="signature"><span class="path">fallbackProviderConfig</span><span class="symbol">.</span><span class="method">stallTimeout</span> <span class="arrow">&rArr;</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The timeout (in ms) after which another <a href="/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><div class="property show-anchors"><div class="signature"><span class="path">fallbackProviderConfig</span><span class="symbol">.</span><span class="method">weight</span> <span class="arrow">&rArr;</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The weight a response from this provider provides. This can be used if a given <a href="/v5/api/providers/provider/">Provider</a> is more trusted, for example.</p>
2020-07-03 08:54:56 +03:00
</div></div><a name="IpcProvider"></a><a name="other-providers--IpcProvider"></a><h2 class="show-anchors"><div>IpcProvider<span class="inherits"> inherits <a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></span><div class="anchors"><a class="self" href="/v5/api/providers/other/#IpcProvider"></a><a class="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>
2020-06-10 06:56:58 +03:00
<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>
<div class="property show-anchors"><div class="signature"><span class="path">ipcProvider</span><span class="symbol">.</span><span class="method">path</span> <span class="arrow">&rArr;</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The path this <a href="/v5/api/providers/provider/">Provider</a> is connected to.</p>
2020-11-23 07:07:13 +03:00
</div></div><a name="UrlJsonRpcProvider"></a><a name="other-providers--UrlJsonRpcProvider"></a><h2 class="show-anchors"><div>UrlJsonRpcProvider<span class="inherits"> inherits <a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></span><div class="anchors"><a class="self" href="/v5/api/providers/other/#UrlJsonRpcProvider"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/url-json-rpc-provider.ts#L50">source</a></div></div></h2><p>This class is intended to be sub-classed and not used directly. It simplifies creating a <a href="/v5/api/providers/provider/">Provider</a> where a normal <a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a> would suffice, with a little extra effort needed to generate the JSON-RPC URL.</p>
2020-06-10 06:56:58 +03:00
<div class="property show-anchors"><div class="signature"><span class="modifier">new </span><span class="path">ethers</span><span class="symbol">.</span><span class="path">providers</span><span class="symbol">.</span><span class="method">UrlJsonRpcProvider</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">apiKey</span> <span class="symbol">]</span> <span class="symbol">]</span> <span class="symbol">)</span><div class="anchors"></div></div><div class="body"><p>Sub-classes do not need to override this. Instead they should override the static method <code class="inline">getUrl</code> and optionally <code class="inline">getApiKey</code>.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">urlJsonRpcProvider</span><span class="symbol">.</span><span class="method">apiKey</span> <span class="arrow">&rArr;</span> <span class="returns">any</span><div class="anchors"></div></div><div class="body"><p>The value of the apiKey that was returned from <code class="inline">InheritedClass.getApiKey</code>.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">InheritingClass</span><span class="symbol">.</span><span class="method">getApiKey</span><span class="symbol">(</span> <span class="param">apiKey</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">any</span><div class="anchors"></div></div><div class="body"><p>This function should examine the <i>apiKey</i> to ensure it is valid and return a (possible modified) value to use in <code class="inline">getUrl</code>.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">InheritingClass</span><span class="symbol">.</span><span class="method">getUrl</span><span class="symbol">(</span> <span class="param">network</span> <span class="symbol">,</span> <span class="param">apiKey</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>The URL to use for the JsonRpcProvider instance.</p>
2020-11-23 07:07:13 +03:00
</div></div><a name="Web3Provider"></a><a name="other-providers--Web3Provider"></a><h2 class="show-anchors"><div>Web3Provider<span class="inherits"> inherits <a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></span><div class="anchors"><a class="self" href="/v5/api/providers/other/#Web3Provider"></a><a class="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 <a href="https://github.com/ethereum/web3.js">web3.js based</a> application to ethers by wrapping an existing Web3-compatible (such as a <a href="https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-http">Web3HttpProvider</a>, <a href="https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-ipc">Web3IpcProvider</a> or <a href="https://github.com/ethereum/web3.js/tree/1.x/packages/web3-providers-ws">Web3WsProvider</a>) and exposing it as an ethers.js <a href="/v5/api/providers/provider/">Provider</a> which can then be used with the rest of the library.</p>
2020-06-10 06:56:58 +03:00
<p>This may also be used to wrap a standard [EIP-1193 Provider](link-eip-1193].</p>
<div class="property show-anchors"><div class="signature"><span class="modifier">new </span><span class="path">ethers</span><span class="symbol">.</span><span class="path">providers</span><span class="symbol">.</span><span class="method">Web3Provider</span><span class="symbol">(</span> <span class="param">externalProvider</span> <span class="symbol">[</span> <span class="symbol">,</span> <span class="param">network</span> <span class="symbol">]</span> <span class="symbol">)</span><div class="anchors"></div></div><div class="body"><p>Create a new <b>Web3Provider</b>, which wraps an <a href="https://eips.ethereum.org/EIPS/eip-1193">EIP-1193 Provider</a> or Web3Provider-compatible Provider.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">web3Provider</span><span class="symbol">.</span><span class="method">provider</span> <span class="arrow">&rArr;</span> <span class="returns">Web3CompatibleProvider</span><div class="anchors"></div></div><div class="body"><p>The provider used to create this instance.</p>
</div></div><a name="Web3Provider--ExternalProvider"></a><a name="other-providers--Web3Provider--Web3Provider--ExternalProvider"></a><h3 class="show-anchors"><div>ExternalProvider<div class="anchors"><a class="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 <a href="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>
<div class="property show-anchors"><div class="signature"><span class="path">externalProvider</span><span class="symbol">.</span><span class="method">request</span><span class="symbol">(</span> <span class="param">request</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">Promise&lt; any &gt;</span><div class="anchors"></div></div><div class="body"><p>This follows the <a href="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 <code class="inline">method</code> and <code class="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><div class="property show-anchors"><div class="signature"><span class="path">externalProvider</span><span class="symbol">.</span><span class="method">sendAsync</span><span class="symbol">(</span> <span class="param">request</span> <span class="symbol">,</span> <span class="param">callback</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">void</span><div class="anchors"></div></div><div class="body"><p>This follows the <a href="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 <code class="inline">method</code> and <code class="inline">params</code>.</p>
<p>The <i>callback</i> should use the error-first calling semantics, so <code class="inline">(error, result)</code> where the result is a JSON-RPC wrapped result.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">externalProvider</span><span class="symbol">.</span><span class="method">send</span><span class="symbol">(</span> <span class="param">request</span> <span class="symbol">,</span> <span class="param">callback</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">void</span><div class="anchors"></div></div><div class="body"><p>This is identical to <code class="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>
2020-11-23 07:07:13 +03:00
</div></div><a name="WebSocketProvider"></a><a name="other-providers--WebSocketProvider"></a><h2 class="show-anchors"><div>WebSocketProvider<span class="inherits"> inherits <a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></span><div class="anchors"><a class="self" href="/v5/api/providers/other/#WebSocketProvider"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/websocket-provider.ts#L46">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>
2020-07-03 08:54:56 +03:00
2020-11-23 07:07:13 +03:00
<p>The WebSocket API is newer, and if running your own infrastructure, note that WebSockets are much more intensive on your server resources, 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>
2020-07-03 08:54:56 +03:00
2020-09-08 08:12:15 +03:00
<div class="property show-anchors"><div class="signature"><span class="modifier">new </span><span class="path">ethers</span><span class="symbol">.</span><span class="path">provider</span><span class="symbol">.</span><span class="method">WebSocketProvider</span><span class="symbol">(</span> <span class="symbol">[</span> <span class="param">url</span> <span class="symbol">[</span> <span class="symbol">,</span> <span class="param">network</span> <span class="symbol">]</span> <span class="symbol">]</span> <span class="symbol">)</span><div class="anchors"></div></div><div class="body"><p>Returns a new <a href="/v5/api/providers/other/#WebSocketProvider">WebSocketProvider</a> connected to <i>url</i> as the <i>network</i>.</p>
2020-07-03 08:54:56 +03:00
<p>If <i>url</i> is unspecified, the default <code class="inline">"ws://localhost:8546"</code> will be used. If <i>network</i> is unspecified, it will be queried from the network.</p>
2020-06-10 06:56:58 +03:00
</div></div>
<div class="footer">
<div class="nav previous"><a href="/v5/api/providers/api-providers/"><span class="arrow">&larr;</span>API Providers</a></div>
<div class="nav next"><a href="/v5/api/providers/types/">Types<span class="arrow">&rarr;</span></a></div>
</div>
2020-11-23 07:07:13 +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 November 22, 2020, 11:5pm.</div>
2020-06-10 06:56:58 +03:00
</div>
<script src="/v5/static/script.js" type="text/javascript"></script>
2020-11-23 07:07:13 +03:00
<!--EXTRASCRIPT-->
2020-06-10 06:56:58 +03:00
</body>
</html>