ethers.js/docs.wrm/api/providers/other.wrm

174 lines
7.3 KiB
Plaintext
Raw Permalink Normal View History

_section: Other Providers
2022-02-03 16:31:40 -05:00
_subsection: FallbackProvider @<FallbackProvider> @INHERIT<[[BaseProvider]]> @SRC<providers/fallback-provider:class.FallbackProvider>
2020-05-08 03:24:40 -04:00
The **FallbackProvider** is the most advanced [[Provider]] available in
2020-02-01 03:39:21 -05:00
ethers.
2020-05-08 03:24:40 -04:00
It uses a quorum and connects to multiple [Providers](Provider) as backends,
2020-02-01 03:39:21 -05:00
each configured with a //priority// and a //weight// .
2020-02-01 03:39:21 -05:00
When a request is made, the request is dispatched to multiple backends, randomly
chosen (lower-value priority backends are always selected first) and the results from
2020-02-01 03:39:21 -05:00
each are compared against the others. Only once the quorum has been reached will that
result be accepted and returned to the caller.
By default the quorum requires 50% (rounded up) of the backends to agree. The //weight//
can be used to give a backend Provider more influence.
_property: new ethers.providers.FallbackProvider(providers [ , quorum ])
Creates a new instance of a FallbackProvider connected to //providers//. If
quorum is not specified, half of the total sum of the provider weights is
used.
2020-05-08 03:24:40 -04:00
The //providers// can be either an array of [[Provider]] or [[FallbackProviderConfig]].
If a [[Provider]] is provided, the defaults are a priority of 1 and a weight of 1.
2020-02-01 03:39:21 -05:00
2020-05-08 03:24:40 -04:00
_property: provider.providerConfigs => Array<[[FallbackProviderConfig]]>
2020-02-01 03:39:21 -05:00
The list of Provider Configurations that describe the backends.
_property: provider.quorum => number
The quorum the backend responses must agree upon before a result will be
resolved. By default this is //half the sum of the weights//.
2020-05-08 03:24:40 -04:00
_heading: FallbackProviderConfig @<FallbackProviderConfig>
2020-02-01 03:39:21 -05:00
2020-05-08 03:24:40 -04:00
_property: fallbackProviderConfig.provider => [[Provider]]
2020-02-01 03:39:21 -05:00
The provider for this configuration.
_property: fallbackProviderConfig.priority => number
The priority used for the provider. Lower-value priorities are favoured over
higher-value priorities. If multiple providers share the same priority, they
are chosen at random.
2020-02-01 03:39:21 -05:00
_property: fallbackProviderConfig.stallTimeout => number
2020-05-08 03:24:40 -04:00
The timeout (in ms) after which another [[Provider]] will be attempted. This
2020-02-01 03:39:21 -05:00
does not affect the current Provider; if it returns a result it is counted
as part of the quorum.
Lower values will result in more network traffic, but may reduce the response
time of requests.
_property: fallbackProviderConfig.weight => number
The weight a response from this provider provides. This can be used if a given
2020-05-08 03:24:40 -04:00
[[Provider]] is more trusted, for example.
2020-02-01 03:39:21 -05:00
2020-05-08 03:24:40 -04:00
_subsection: IpcProvider @<IpcProvider> @INHERIT<[[JsonRpcProvider]]> @SRC<providers:class.IpcProvider>
2020-02-01 03:39:21 -05:00
The **IpcProvider** allows the JSON-RPC API to be used over a local
filename on the file system, exposed by Geth, Parity and other nodes.
This is only available in //node.js// (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.
_property: ipcProvider.path => string
2020-05-08 03:24:40 -04:00
The path this [[Provider]] is connected to.
2020-02-01 03:39:21 -05:00
2022-03-19 02:48:17 -04:00
_subsection: JsonRpcBatchProvider @<JsonRpcBatchProvider> @INHERIT<[[JsonRpcProvider]]> @SRC<providers:class.JsonRpcBatchProvider>
The **JsonRpcBatchProvider** operated identically to any other Provider,
except the calls are implicly batched during an event-loop and sent using
the JSON-RPC batch protocol to the backend.
This results in fewer connections and fewer requests, which may result
in lower costs or faster responses, depending on your use case.
Keep in mind some backends may not support batched requests.
2020-05-08 03:24:40 -04:00
_subsection: UrlJsonRpcProvider @<UrlJsonRpcProvider> @INHERIT<[[JsonRpcProvider]]> @SRC<providers:class.UrlJsonRpcProvider>
2020-02-01 03:39:21 -05:00
This class is intended to be sub-classed and not used directly. It
2020-05-08 03:24:40 -04:00
simplifies creating a [[Provider]] where a normal [[JsonRpcProvider]]
2020-02-01 03:39:21 -05:00
would suffice, with a little extra effort needed to generate the JSON-RPC
URL.
_property: new ethers.providers.UrlJsonRpcProvider([ network [ , apiKey ] ])
Sub-classes do not need to override this. Instead they should override the
static method ``getUrl`` and optionally ``getApiKey``.
_property: urlJsonRpcProvider.apiKey => any
The value of the apiKey that was returned from ``InheritedClass.getApiKey``.
2020-02-01 03:39:21 -05:00
_property: InheritingClass.getApiKey(apiKey) => any
This function should examine the //apiKey// to ensure it is valid and
return a (possible modified) value to use in ``getUrl``.
2020-02-01 03:39:21 -05:00
_property: InheritingClass.getUrl(network, apiKey) => string
The URL to use for the JsonRpcProvider instance.
2020-01-10 01:01:00 -05:00
2020-06-17 23:38:59 -04:00
_subsection: Web3Provider @<Web3Provider> @INHERIT<[[JsonRpcProvider]]> @SRC<providers:class.Web3Provider>
2020-01-10 01:01:00 -05:00
2020-02-02 07:58:29 -05:00
The Web3Provider is meant to ease moving from a [web3.js based](link-web3)
2020-10-03 13:30:15 -03:00
application to ethers by wrapping an existing Web3-compatible (such as a
2020-06-12 03:38:55 -04:00
[Web3HttpProvider](link-web3-http), [Web3IpcProvider](link-web3-ipc) or
2020-05-08 03:24:40 -04:00
[Web3WsProvider](link-web3-ws)) and exposing it as an ethers.js [[Provider]]
2020-02-02 07:58:29 -05:00
which can then be used with the rest of the library.
2020-01-10 01:01:00 -05:00
2021-07-01 23:22:14 -04:00
This may also be used to wrap a standard [EIP-1193 Provider](link-eip-1193).
2020-06-12 03:38:55 -04:00
_property: new ethers.providers.Web3Provider(externalProvider [, network ])
Create a new **Web3Provider**, which wraps an [EIP-1193 Provider](link-eip-1193) or
2020-02-01 03:39:21 -05:00
Web3Provider-compatible Provider.
2020-01-10 01:01:00 -05:00
2020-02-01 03:39:21 -05:00
_property: web3Provider.provider => Web3CompatibleProvider
The provider used to create this instance.
2020-01-10 01:01:00 -05:00
2020-06-12 03:38:55 -04:00
_heading: ExternalProvider @<Web3Provider--ExternalProvider>
An **ExternalProvider** can be either one for the above mentioned Web3
Providers (or otherwise compatible) or an [[link-eip-1193]] provider.
An ExternalProvider must offer one of the following signatures, and the
first matching is used:
_property: externalProvider.request(request) => Promise<any>
This follows the [[link-eip-1193]] API signature.
The //request// should be a standard JSON-RPC payload, which should at
a minimum specify the ``method`` and ``params``.
The result should be the actual result, which differs from the Web3.js
response, which is a wrapped JSON-RPC response.
_property: externalProvider.sendAsync(request, callback) => void
This follows the [Web3.js Provider Signature](link-web3-send).
The //request// should be a standard JSON-RPC payload, which should at
a minimum specify the ``method`` and ``params``.
The //callback// should use the error-first calling semantics, so
``(error, result)`` where the result is a JSON-RPC wrapped result.
_property: externalProvider.send(request, callback) => void
This is identical to ``sendAsync``. 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
2020-06-17 23:38:59 -04:00
_subsection: WebSocketProvider @<WebSocketProvider> @INHERIT<[[JsonRpcProvider]]> @SRC<providers:class.WebSocketProvider>
The **WebSocketProvider** 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.
The WebSocket API is newer, and if running your own infrastructure, note that
2020-11-22 23:03:50 -05:00
WebSockets are much more intensive on your server resources, as they must manage
2020-06-17 23:38:59 -04:00
and maintain the state for each client. For this reason, many services may also
charge additional fees for using their WebSocket endpoints.
_property: new ethers.providers.WebSocketProvider([ url [ , network ] ])
2020-06-17 23:38:59 -04:00
Returns a new [[WebSocketProvider]] connected to //url// as the //network//.
If //url// is unspecified, the default ``"ws:/\/localhost:8546"`` will be used.
If //network// is unspecified, it will be queried from the network.