JsonRpcProvider inherits BaseProvider

The JSON-RPC API is a popular method for interacting with Ethereum and is available in all major Ethereum node implementations (e.g. Geth and Parity) as well as many third-party web services (e.g. INFURA)

new ethers.providers.JsonRpcProvider( [ urlOrConnectionInfo [ , networkish ] ] )

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 node using eth_chainId and falling back on eth_networkId.

Note: Connecting to a Local Node

Each node implementation is slightly different and may require specific command-line flags, configuration or settings in their UI to enable JSON-RPC, unlock accounts or expose specific APIs. Please consult their documentation.

jsonRpcProvider.connection ConnectionInfo

The fully formed ConnectionInfo the Provider is connected to.

jsonRpcProvider.getSigner( [ addressOrIndex ] ) JsonRpcSigner

Returns a JsonRpcSigner which is managed by this Ethereum node, at addressOrIndex. If no addressOrIndex is provided, the first account (account #0) is used.

jsonRpcProvider.getUncheckedSigner( [ addressOrIndex ] ) JsonRpcUncheckedSigner
jsonRpcProvider.listAccounts( ) Promise< Array< string > >

Returns a list of all account addresses managed by this provider.

jsonRpcProvider.send( method , params ) Promise< any >

Allows sending raw messages to the provider.

This can be used for backend-specific calls, such as for debugging or specific account management.

JsonRpcSigner inherits Signer

A JsonRpcSigner is a simple Signer which is backed by a connected JsonRpcProvider.

signer.provider JsonRpcProvider

The provider this signer was established from.

signer.connectUnchecked( ) JsonRpcUncheckedSigner

Returns a new Signer object which does not perform additional checks when sending a transaction. See getUncheckedSigner for more details.

signer.sendUncheckedTransaction( transaction ) Promise< string< DataHexString< 32 > > >

Sends the transaction and returns a Promise which resolves to the opaque transaction hash.

signer.unlock( password ) Promise< boolean >

Request the node unlock the account (if locked) using password.

JsonRpcUncheckedSigner inherits 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 JsonRpcSigner immediately queries the provider for the details using the returned transaction hash to populate the 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 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.

StaticJsonRpcProvider inherits JsonRpcProvider

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.

Node-Specific Methods

Many methods are less common or specific to certain Ethereum Node implementations (e.g. Parity vs Geth. These include account and admin management, debugging, deeper block and transaction exploration and other services (such as Swarm and Whisper).

The jsonRpcProvider.send method can be used to access these.