ethers.js/docs.wrm/api/providers/jsonrpc-provider.wrm

74 lines
3.7 KiB
Plaintext
Raw Normal View History

2020-02-01 11:39:21 +03:00
_section: JsonRpcProvider @<provider-jsonrpc> @INHERIT<[[provider]]>
2020-02-02 15:58:29 +03:00
The [JSON-RPC API](link-jsonrpc) is a
2020-02-01 11:39:21 +03:00
very popular method for interacting with Ethereum and is available in all
2020-02-02 15:58:29 +03:00
major Ethereum node implementations (e.g. [Geth](link-geth)
and [Parity](link-parity)) as well as many third-party web
services (e.g. [INFURA](link-infura))
2020-02-01 11:39:21 +03:00
_property: new ethers.providers.JsonRpcProvider([ url [ , aNetworkish ] ])
2020-04-17 05:25:05 +03:00
Connect to a JSON-RPC API located at //url// using the //aNetworkish// network.
If //url// is not specified, the default (i.e. ``http:/\/localhost:8545``) is used
2020-02-01 11:39:21 +03:00
and if no network is specified, it will be determined automatically by
querying the node.
2020-02-01 11:39:21 +03:00
_note: Note: Connecting to a Local Node
Each node implementation is slightly different and may require specific command-line
flags or changes in their Settings UI to enable JSON-RPC, unlock accounrs
or expose specific APIs. Please consult theit documentation.
2020-02-01 11:39:21 +03:00
_property: jsonRpcProvider.getSigner([ addressOrIndex ]) => [[signer-jsonrpc]] @<provider-jsonrpc-getsigner> @SRC<providers/json-rpc-provider>
Returns a [[signer-jsonrpc]] which is managed by this Ethereum node, at
//addressOrIndex//. If no //addressOrIndex// is provided, the first
account (account #0) is used.
2020-02-01 11:39:21 +03:00
_property: jsonRpcProvider.getUncheckedSigner([ addressOrIndex ]) => [[provider-jsonrpc-uncheckedsigner]] @<provider-jsonrpc-getuncheckedsigner> @SRC<providers/json-rpc-provider>
2020-02-01 11:39:21 +03:00
_property: jsonRpcProvider.listAccounts() => Array<string> @<provider-jsonrpc-listaccounts> @SRC<providers/json-rpc-provider>
Returns a list of all account addresses managed by this provider.
2020-01-10 09:01:00 +03:00
2020-02-01 11:39:21 +03:00
_property: jsonRpcProvider.send(method, params) => Promise<any> @<provider-jsonrpc-send> @SRC<providers/json-rpc-provider>
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
2020-02-01 11:39:21 +03:00
_subsection: JsonRpcSigner @<signer-jsonrpc> @INHERIT<[[signer]]>
A **JsonRpcSigner** is a simple Signer which is backed by a connected
[[provider-jsonrpc]].
_property: signer.provider => [[provider-jsonrpc]]
The provider this signer was established from.
_property: signer.connectUnchecked() => [[provider-jsonrpc-uncheckedsigner]]
Returns a new Signer object which does not perform addtional checks when
sending a transaction. See [[provider-jsonrpc-uncheckedsigner]] for more details.
_property: signer.sendUncheckedTransaction(transaction) => Promise<string<[[datahexstring]]<32>>>
Sends the //transaction// and returns a Promise which resolves to the
opacque transaction hash.
_property: signer.unlock(password) => Promise<boolean>
Request the node unlock the account (if locked) using //password//.
_subsection: JsonRpcUncheckedSigner @<provider-jsonrpc-uncheckedsigner> @INHERIT<[[signer]]>
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.
To remedy this, the [[signer-jsonrpc]] immeidately queries the provider for
the details using the returned transaction hash to populate the [[provider-transactionresponse]]
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
immediately return the result as a mock [[provider-transactionresponse]]-like
object, with most of the properties set to null, but allows access to the
transaction hash quickly, if that is all that is required.