2022-02-04 00:31:40 +03:00
|
|
|
_section: JsonRpcProvider @<JsonRpcProvider> @INHERIT<[[BaseProvider]]> @SRC<providers:class.JsonRpcProvider>
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-07-14 14:13:52 +03:00
|
|
|
The [JSON-RPC API](link-jsonrpc) is a popular method for interacting
|
2020-05-08 10:24:40 +03:00
|
|
|
with Ethereum and is available in all major Ethereum node implementations
|
|
|
|
(e.g. [[link-geth]] and [[link-parity]]) as well as many
|
|
|
|
third-party web services (e.g. [[link-infura]])
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2021-02-05 01:17:55 +03:00
|
|
|
_property: new ethers.providers.JsonRpcProvider([ urlOrConnectionInfo [ , networkish ] ]) @SRC<providers:constructor.JsonRpcProvider>
|
|
|
|
Connect to a JSON-RPC HTTP API using the URL or [[ConnectionInfo]] //urlOrConnectionInfo//
|
|
|
|
connected to the //networkish// network.
|
|
|
|
|
|
|
|
If //urlOrConnectionInfo// is not specified, the default (i.e. ``http:/\/localhost:8545``)
|
|
|
|
is used and if no network is specified, it will be determined automatically by querying the
|
2022-04-29 22:34:58 +03:00
|
|
|
node using ``eth_chainId`` and falling back on ``eth_networkId``.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-01 11:39:21 +03:00
|
|
|
_note: Note: Connecting to a Local Node
|
2020-05-08 10:24:40 +03:00
|
|
|
Each node implementation is slightly different and may require specific
|
|
|
|
command-line flags, configuration or settings in their UI to enable
|
2020-07-03 08:44:17 +03:00
|
|
|
JSON-RPC, unlock accounts or expose specific APIs. Please consult
|
2020-05-08 10:24:40 +03:00
|
|
|
their documentation.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2022-01-31 06:45:46 +03:00
|
|
|
_property: jsonRpcProvider.connection => [[ConnectionInfo]]
|
|
|
|
The fully formed [[ConnectionInfo]] the Provider is connected to.
|
|
|
|
|
2020-05-08 10:24:40 +03:00
|
|
|
_property: jsonRpcProvider.getSigner([ addressOrIndex ]) => [[JsonRpcSigner]] @<JsonRpcProvider-getSigner> @SRC<providers/json-rpc-provider>
|
|
|
|
Returns a [[JsonRpcSigner]] which is managed by this Ethereum node, at
|
2019-08-21 08:53:47 +03:00
|
|
|
//addressOrIndex//. If no //addressOrIndex// is provided, the first
|
|
|
|
account (account #0) is used.
|
|
|
|
|
2020-05-08 10:24:40 +03:00
|
|
|
_property: jsonRpcProvider.getUncheckedSigner([ addressOrIndex ]) => [[UncheckedJsonRpcSigner]] @<JsonRpcProvider-getUncheckedSigner> @SRC<providers/json-rpc-provider>
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2021-08-09 21:35:43 +03:00
|
|
|
_property: jsonRpcProvider.listAccounts() => Promise<Array<string>> @<JsonRpcProvider-listAccounts> @SRC<providers/json-rpc-provider>
|
2020-02-01 11:39:21 +03:00
|
|
|
Returns a list of all account addresses managed by this provider.
|
2020-01-10 09:01:00 +03:00
|
|
|
|
2020-05-08 10:24:40 +03:00
|
|
|
_property: jsonRpcProvider.send(method, params) => Promise<any> @<JsonRpcProvider-send> @SRC<providers/json-rpc-provider>
|
2020-02-01 11:39:21 +03:00
|
|
|
Allows sending raw messages to the provider.
|
2020-01-10 09:01:00 +03:00
|
|
|
|
2020-02-01 11:39:21 +03:00
|
|
|
This can be used for backend-specific calls, such as for debugging or
|
|
|
|
specific account management.
|
2020-01-10 09:01:00 +03:00
|
|
|
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-05-08 10:24:40 +03:00
|
|
|
_subsection: JsonRpcSigner @<JsonRpcSigner> @INHERIT<[[Signer]]> @SRC<providers:class.JsonRpcSigner>
|
2020-02-01 11:39:21 +03:00
|
|
|
A **JsonRpcSigner** is a simple Signer which is backed by a connected
|
2020-05-08 10:24:40 +03:00
|
|
|
[[JsonRpcProvider]].
|
2020-02-01 11:39:21 +03:00
|
|
|
|
2020-05-08 10:24:40 +03:00
|
|
|
_property: signer.provider => [[JsonRpcProvider]]
|
2020-02-01 11:39:21 +03:00
|
|
|
The provider this signer was established from.
|
|
|
|
|
2020-05-08 10:24:40 +03:00
|
|
|
_property: signer.connectUnchecked() => [[UncheckedJsonRpcSigner]] @<JsonRpcSigner-connectUnchecked> @SRC<providers>
|
2020-07-03 08:44:17 +03:00
|
|
|
Returns a new Signer object which does not perform additional checks when
|
2020-05-08 10:24:40 +03:00
|
|
|
sending a transaction. See [getUncheckedSigner](JsonRpcProvider-getUncheckedSigner) for more details.
|
2020-02-01 11:39:21 +03:00
|
|
|
|
2020-05-08 10:24:40 +03:00
|
|
|
_property: signer.sendUncheckedTransaction(transaction) => Promise<string<[[DataHexString]]\<32>\>> @<JsonRpcSigner-sendUncheckedTransaction> @SRC<providers>
|
2020-02-01 11:39:21 +03:00
|
|
|
Sends the //transaction// and returns a Promise which resolves to the
|
2020-07-03 08:44:17 +03:00
|
|
|
opaque transaction hash.
|
2020-02-01 11:39:21 +03:00
|
|
|
|
2020-05-08 10:24:40 +03:00
|
|
|
_property: signer.unlock(password) => Promise<boolean> @<JsonRpcSigner-unlock> @SRC<providers>
|
2020-02-01 11:39:21 +03:00
|
|
|
Request the node unlock the account (if locked) using //password//.
|
|
|
|
|
|
|
|
|
2020-05-08 10:24:40 +03:00
|
|
|
_subsection: JsonRpcUncheckedSigner @<UncheckedJsonRpcSigner> @INHERIT<[[Signer]]> @SRC<providers:class.UncheckedJsonRpcSigner>
|
2020-02-01 11:39:21 +03:00
|
|
|
The JSON-RPC API only provides a transaction hash as the response when a
|
|
|
|
transaction is sent, but the ethers Provider requires populating all details
|
|
|
|
of a transaction before returning it. For example, the gas price and gas limit
|
|
|
|
may be adjusted by the node or the nonce automatically included, in which case
|
|
|
|
the opaque transaction hash has discarded this.
|
|
|
|
|
2020-07-03 08:44:17 +03:00
|
|
|
To remedy this, the [[JsonRpcSigner]] immediately queries the provider for
|
2020-05-08 10:24:40 +03:00
|
|
|
the details using the returned transaction hash to populate the [[providers-TransactionResponse]]
|
2020-02-01 11:39:21 +03:00
|
|
|
object.
|
|
|
|
|
|
|
|
Some backends do not respond immediately and instead defer releasing the
|
|
|
|
details of a transaction it was responsible for signing until it is mined.
|
|
|
|
|
|
|
|
The **UncheckedSigner** does not populate any additional information and will
|
2020-05-08 10:24:40 +03:00
|
|
|
immediately return the result as a mock [[providers-TransactionResponse]]-like
|
2020-02-01 11:39:21 +03:00
|
|
|
object, with most of the properties set to null, but allows access to the
|
|
|
|
transaction hash quickly, if that is all that is required.
|
2020-05-08 10:24:40 +03:00
|
|
|
|
|
|
|
|
2021-08-09 22:02:37 +03:00
|
|
|
_subsection: StaticJsonRpcProvider @<StaticJsonRpcProvider> @INHERIT<[[JsonRpcProvider]]> @SRC<providers:class.StaticJsonRpcProvider>
|
|
|
|
|
|
|
|
An ethers Provider will execute frequent ``getNetwork`` calls to ensure
|
|
|
|
the network calls and network being communicated with are consistent.
|
|
|
|
|
|
|
|
In the case of a client like MetaMask, this is desired as the network
|
|
|
|
may be changed by the user at any time, in such cases the cost of
|
|
|
|
checking the chainId is local and therefore cheap.
|
|
|
|
|
|
|
|
However, there are also many times where it is known the network cannot
|
|
|
|
change, such as when connecting to an INFURA endpoint, in which case,
|
|
|
|
the **StaticJsonRpcProvider** can be used which will indefinitely cache
|
|
|
|
the chain ID, which can reduce network traffic and reduce round-trip
|
|
|
|
queries for the chain ID.
|
|
|
|
|
|
|
|
This [[Provider]] should **only** be used when it is known the network
|
|
|
|
cannot change.
|
|
|
|
|
|
|
|
|
2020-05-08 10:24:40 +03:00
|
|
|
_subsection: Node-Specific Methods @<JsonRpcProvider--other>
|
|
|
|
|
|
|
|
Many methods are less common or specific to certain Ethereum Node implementations
|
|
|
|
(e.g. [Parity](link-parity) vs [Geth](link-geth). These include account and admin management,
|
|
|
|
debugging, deeper block and transaction exploration and other services (such as
|
|
|
|
Swarm and Whisper).
|
|
|
|
|
|
|
|
The [jsonRpcProvider.send](JsonRpcProvider-send) method can be used to access these.
|
|
|
|
|
|
|
|
- [All JSON-RPC methods](link-json-rpc) (including the less common methods) which most
|
|
|
|
Ethereum Nodes support.
|
|
|
|
- [Parity's Trace Module](link-parity-trace) can be used to trace and debug EVM
|
2020-07-03 08:44:17 +03:00
|
|
|
execution of a transaction (requires custom configuration)
|
2020-05-08 10:24:40 +03:00
|
|
|
- [Geth's Debug Module](link-geth-debug) can be used to debug transactions and
|
|
|
|
internal cache state, etc.
|
|
|
|
- [Additional Geth Methods](link-geth-rpc)
|
|
|
|
- [Additional Parity Methods](link-parity-rpc)
|