- Types
- JsonRpcApiPollingProvider
- JsonRpcApiProvider
- JsonRpcProvider
- JsonRpcSigner
- JsonRpcTransactionRequest
When subscribing to the "debug" event, the Listener will receive this object as the first parameter.
Options for configuring a JsonRpcApiProvider. Much of this is targetted towards sub-classes, which often will not expose any of these options to their consumers.
polling - use the polling strategy is used immediately for events; otherwise, attempt to use filters and fall back onto polling (default: false)
staticNetwork - do not request chain ID on requests to validate the underlying chain has not changed (default: null)
This should ONLY be used if it is certain that the network cannot change, such as when using INFURA (since the URL dictates the network). If the network is assumed static and it does change, this can have tragic consequences. For example, this CANNOT be used with MetaMask, since the used can select a new network from the drop-down at any time.
batchStallTime - how long (ms) to aggregate requests into a single batch. 0 indicates batching will only encompass the current event loop. If batchMaxCount = 1, this is ignored. (default: 10)
batchMaxSize - target maximum size (bytes) to allow per batch request (default: 1Mb)
batchMaxCount - maximum number of requests to allow in a batch. If batchMaxCount = 1, then batching is disabled. (default: 100)
A JSON-RPC error, which are returned on failure from a JSON-RPC server.
A JSON-RPC payload, which are sent to a JSON-RPC server.
A JSON-RPC result, which are returned on success from a JSON-RPC server.
The polling interval (default: 4000 ms)
The JsonRpcApiProvider is an abstract class and MUST be sub-classed.
It provides the base for all JSON-RPC-based Provider interaction.
Sub-classing Notes:
- a sub-class MUST override _send
- a sub-class MUST call the `_start()` method once connected
Gets the Network this provider has committed to. On each call, the network is detected, and if it has changed, the call will reject.
Returns the value associated with the option key.
Sub-classes can use this to inquire about configuration options.
Sends a JSON-RPC payload (or a batch) to the underlying channel.
Sub-classes MUST override this.
Resolves once the _start has been called. This can be used in sub-classes to defer sending data until the connection has been established.
Returns an ethers-style Error for the given JSON-RPC error payload, coalescing the various strings and error shapes that different nodes return, coercing them into a machine-readable standardized error.
Returns the request method and arguments required to perform req.
Returns tx as a normalized JSON-RPC transaction request, which has all values hexlified and any numeric values converted to Quantity values.
Resolves to the Signer account for address managed by the client.
If the address is a number, it is used as an index in the the accounts from listAccounts.
This can only be used on clients which manage accounts (such as Geth with imported account or MetaMask).
Throws if the account doesn't exist.
Requests the method with params via the JSON-RPC protocol over the underlying channel. This can be used to call methods on the backend that do not have a high-level API within the Provider API.
This method queues requests according to the batch constraints in the options, assigns the request a unique ID.
Do NOT override this method in sub-classes; instead override _send or force the options values in the call to the constructor to modify this method's behavior.
The JsonRpcProvider is one of the most common Providers, which performs all operations over HTTP (or HTTPS) requests.
Events are processed by polling the backend for the current block number; when it advances, all block-base events are then checked for updates.