ethers.js/docs/v5/api/providers/jsonrpc-provider/index.html
2020-07-03 01:54:56 -04:00

69 lines
19 KiB
HTML

<!DOCTYPE html>
<html class="paged">
<head>
<title>JsonRpcProvider</title>
<link rel="stylesheet" type="text/css" href="/v5/static/style.css">
</head>
<body>
<div class="sidebar">
<div class="header">
<div class="logo"><a href="/v5/"><div class="image"></div><div class="name">ethers</div><div class="version">v5.0</div></a></div>
</div>
<div class="toc"><div>
<div class="link title"><a href="/v5/">Documentation</a></div><div class="base show link depth-1"><a href="/v5/getting-started/">Getting Started</a></div><div class="base show link depth-1"><a href="/v5/concepts/">Ethereum Basics</a></div><div class="hide link depth-2"><a href="/v5/concepts/events/">Events</a></div><div class="hide link depth-2"><a href="/v5/concepts/gas/">Gas</a></div><div class="hide link depth-2"><a href="/v5/concepts/security/">Security</a></div><div class="base ancestor show link depth-1"><a href="/v5/api/">Application Programming Interface</a></div><div class="show link depth-2"><a href="/v5/api/contract/">Contract Interaction</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract/">Contract</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract-factory/">ContractFactory</a></div><div class="hide link depth-3"><a href="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><div class="show link depth-2"><a href="/v5/api/signer/">Signers</a></div><div class="ancestor show link depth-2"><a href="/v5/api/providers/">Providers</a></div><div class="show link depth-3"><a href="/v5/api/providers/provider/">Provider</a></div><div class="myself ancestor ancestor show link depth-3"><a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><div class="show link depth-3"><a href="/v5/api/providers/api-providers/">API Providers</a></div><div class="show link depth-3"><a href="/v5/api/providers/other/">Other Providers</a></div><div class="show link depth-3"><a href="/v5/api/providers/types/">Types</a></div><div class="show link depth-2"><a href="/v5/api/utils/">Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/abi/">Application Binary Interface</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/coder/">AbiCoder</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/formats/">ABI Formats</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/fragments/">Fragments</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/interface/">Interface</a></div><div class="hide link depth-3"><a href="/v5/api/utils/address/">Addresses</a></div><div class="hide link depth-3"><a href="/v5/api/utils/bignumber/">BigNumber</a></div><div class="hide link depth-3"><a href="/v5/api/utils/bytes/">Byte Manipulation</a></div><div class="hide link depth-3"><a href="/v5/api/utils/constants/">Constants</a></div><div class="hide link depth-3"><a href="/v5/api/utils/display-logic/">Display Logic and Input</a></div><div class="hide link depth-3"><a href="/v5/api/utils/encoding/">Encoding Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/fixednumber/">FixedNumber</a></div><div class="hide link depth-3"><a href="/v5/api/utils/hashing/">Hashing Algorithms</a></div><div class="hide link depth-3"><a href="/v5/api/utils/hdnode/">HD Wallet</a></div><div class="hide link depth-3"><a href="/v5/api/utils/logger/">Logging</a></div><div class="hide link depth-3"><a href="/v5/api/utils/properties/">Property Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/signing-key/">Signing Key</a></div><div class="hide link depth-3"><a href="/v5/api/utils/strings/">Strings</a></div><div class="hide link depth-3"><a href="/v5/api/utils/transactions/">Transactions</a></div><div class="hide link depth-3"><a href="/v5/api/utils/web/">Web Utilities</a></div><div class="hide link depth-3"><a href="/v5/api/utils/wordlists/">Wordlists</a></div><div class="show link depth-2"><a href="/v5/api/other/">Other Libraries</a></div><div class="hide link depth-3"><a href="/v5/api/other/assembly/">Assembly</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/api/">Utilities</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/ast/">Abstract Syntax Tree</a></div><div class="hide link depth-3"><a href="/v5/api/other/hardware/">Hardware Wallets</a></div><div class="show link depth-2"><a href="/v5/api/experimental/">Experimental</a></div><div class="base show link depth-1"><a href="/v5/cli/">Command Line Interfaces</a></div><div class="hide link depth-2"><a href="/v5/cli/ethers/">Sandbox Utility</a></div><div class="hide link depth-2"><a href="/v5/cli/asm/">Assembler</a></div><div class="hide link depth-2"><a href="/v5/cli/ens/">Ethereum Naming Service</a></div><div class="hide link depth-2"><a href="/v5/cli/typescript/">TypeScript</a></div><div class="hide link depth-2"><a href="/v5/cli/plugin/">Making Your Own</a></div><div class="base show link depth-1"><a href="/v5/cookbook/">Cookbook</a></div><div class="base show link depth-1"><a href="/v5/migration/">Migration Guide</a></div><div class="hide link depth-2"><a href="/v5/migration/web3/">Migration: From Web3.js</a></div><div class="hide link depth-2"><a href="/v5/migration/ethers-v4/">Migration: From Ethers v4</a></div><div class="base show link depth-1"><a href="/v5/testing/">Testing</a></div><div class="base show link depth-1"><a href="/v5/contributing/">Contributing and Hacking</a></div><div class="base show link depth-1"><a href="/v5/documentation/">Flatworm Docs</a></div><div class="base show link depth-1"><a href="/v5/license/">License and Copyright</a></div>
</div></div>
</div>
<div class="content">
<div class="breadcrumbs"><a href="/v5/">Documentation</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="/v5/api/">API</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="/v5/api/providers/">Providers</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<span class="current">JsonRpcProvider</span></div>
<a name="JsonRpcProvider"></a><a name="JsonRpcProvider"></a><h1 class="show-anchors"><div>JsonRpcProvider<span class="inherits"> inherits <a href="/v5/api/providers/provider/">Provider</a></span><div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#JsonRpcProvider"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L220">source</a></div></div></h1><p>The <a href="https://github.com/ethereum/wiki/wiki/JSON-RPC">JSON-RPC API</a> is a very popular method for interacting with Ethereum and is available in all major Ethereum node implementations (e.g. <a href="https://geth.ethereum.org">Geth</a> and <a href="https://www.parity.io">Parity</a>) as well as many third-party web services (e.g. <a href="https://infura.io">INFURA</a>)</p>
<div class="property show-anchors"><div class="signature"><span class="modifier">new </span><span class="path">ethers</span><span class="symbol">.</span><span class="path">providers</span><span class="symbol">.</span><span class="method">JsonRpcProvider</span><span class="symbol">(</span> <span class="symbol">[</span> <span class="param">url</span> <span class="symbol">[</span> <span class="symbol">,</span> <span class="param">aNetworkish</span> <span class="symbol">]</span> <span class="symbol">]</span> <span class="symbol">)</span><div class="anchors"><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L226">source</a></div></div><div class="body"><p>Connect to a JSON-RPC API located at <i>url</i> using the <i>aNetworkish</i> network. If <i>url</i> is not specified, the default (i.e. <code class="inline">http://localhost:8545</code>) is used and if no network is specified, it will be determined automatically by querying the node.</p>
</div></div><div class="definition container-box note"><div class="term">Note: Connecting to a Local Node</div><div class="body"><p>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.</p>
</div></div><a name="JsonRpcProvider-getSigner"></a><div class="property show-anchors"><div class="signature"><span class="path">jsonRpcProvider</span><span class="symbol">.</span><span class="method">getSigner</span><span class="symbol">(</span> <span class="symbol">[</span> <span class="param">addressOrIndex</span> <span class="symbol">]</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/providers/jsonrpc-provider/#JsonRpcSigner">JsonRpcSigner</a></span><div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#JsonRpcProvider-getSigner"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L294">source</a></div></div><div class="body"><p>Returns a <a href="/v5/api/providers/jsonrpc-provider/#JsonRpcSigner">JsonRpcSigner</a> which is managed by this Ethereum node, at <i>addressOrIndex</i>. If no <i>addressOrIndex</i> is provided, the first account (account #0) is used.</p>
</div></div><a name="JsonRpcProvider-getUncheckedSigner"></a><div class="property show-anchors"><div class="signature"><span class="path">jsonRpcProvider</span><span class="symbol">.</span><span class="method">getUncheckedSigner</span><span class="symbol">(</span> <span class="symbol">[</span> <span class="param">addressOrIndex</span> <span class="symbol">]</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/providers/jsonrpc-provider/#UncheckedJsonRpcSigner">JsonRpcUncheckedSigner</a></span><div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#JsonRpcProvider-getUncheckedSigner"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L298">source</a></div></div><div class="body">
</div></div><a name="JsonRpcProvider-listAccounts"></a><div class="property show-anchors"><div class="signature"><span class="path">jsonRpcProvider</span><span class="symbol">.</span><span class="method">listAccounts</span><span class="symbol">(</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">Array&lt; string &gt;</span><div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#JsonRpcProvider-listAccounts"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L302">source</a></div></div><div class="body"><p>Returns a list of all account addresses managed by this provider.</p>
</div></div><a name="JsonRpcProvider-send"></a><div class="property show-anchors"><div class="signature"><span class="path">jsonRpcProvider</span><span class="symbol">.</span><span class="method">send</span><span class="symbol">(</span> <span class="param">method</span> <span class="symbol">,</span> <span class="param">params</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">Promise&lt; any &gt;</span><div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#JsonRpcProvider-send"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L308">source</a></div></div><div class="body"><p>Allows sending raw messages to the provider.</p>
<p>This can be used for backend-specific calls, such as for debugging or specific account management.</p>
</div></div><a name="JsonRpcSigner"></a><a name="JsonRpcProvider--JsonRpcSigner"></a><h2 class="show-anchors"><div>JsonRpcSigner<span class="inherits"> inherits <a href="/v5/api/signer/#Signer">Signer</a></span><div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#JsonRpcSigner"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L46">source</a></div></div></h2><p>A <b>JsonRpcSigner</b> is a simple Signer which is backed by a connected <a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a>.</p>
<div class="property show-anchors"><div class="signature"><span class="path">signer</span><span class="symbol">.</span><span class="method">provider</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></span><div class="anchors"></div></div><div class="body"><p>The provider this signer was established from.</p>
</div></div><a name="JsonRpcSigner-connectUnchecked"></a><div class="property show-anchors"><div class="signature"><span class="path">signer</span><span class="symbol">.</span><span class="method">connectUnchecked</span><span class="symbol">(</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns"><a href="/v5/api/providers/jsonrpc-provider/#UncheckedJsonRpcSigner">JsonRpcUncheckedSigner</a></span><div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#JsonRpcSigner-connectUnchecked"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L83">source</a></div></div><div class="body"><p>Returns a new Signer object which does not perform additional checks when sending a transaction. See <a href="/v5/api/providers/jsonrpc-provider/#JsonRpcProvider-getUncheckedSigner">getUncheckedSigner</a> for more details.</p>
</div></div><a name="JsonRpcSigner-sendUncheckedTransaction"></a><div class="property show-anchors"><div class="signature"><span class="path">signer</span><span class="symbol">.</span><span class="method">sendUncheckedTransaction</span><span class="symbol">(</span> <span class="param">transaction</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">Promise&lt; string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 32 &gt; &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#JsonRpcSigner-sendUncheckedTransaction"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L102">source</a></div></div><div class="body"><p>Sends the <i>transaction</i> and returns a Promise which resolves to the opaque transaction hash.</p>
</div></div><a name="JsonRpcSigner-unlock"></a><div class="property show-anchors"><div class="signature"><span class="path">signer</span><span class="symbol">.</span><span class="method">unlock</span><span class="symbol">(</span> <span class="param">password</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">Promise&lt; boolean &gt;</span><div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#JsonRpcSigner-unlock"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L188">source</a></div></div><div class="body"><p>Request the node unlock the account (if locked) using <i>password</i>.</p>
</div></div><a name="UncheckedJsonRpcSigner"></a><a name="JsonRpcProvider--UncheckedJsonRpcSigner"></a><h2 class="show-anchors"><div>JsonRpcUncheckedSigner<span class="inherits"> inherits <a href="/v5/api/signer/#Signer">Signer</a></span><div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#UncheckedJsonRpcSigner"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L197">source</a></div></div></h2><p>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.</p>
<p>To remedy this, the <a href="/v5/api/providers/jsonrpc-provider/#JsonRpcSigner">JsonRpcSigner</a> immediately queries the provider for the details using the returned transaction hash to populate the <a href="/v5/api/providers/types/#providers-TransactionResponse">TransactionResponse</a> object.</p>
<p>Some backends do not respond immediately and instead defer releasing the details of a transaction it was responsible for signing until it is mined.</p>
<p>The <b>UncheckedSigner</b> does not populate any additional information and will immediately return the result as a mock <a href="/v5/api/providers/types/#providers-TransactionResponse">TransactionResponse</a>-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.</p>
<a name="JsonRpcProvider--other"></a><a name="JsonRpcProvider--JsonRpcProvider--other"></a><h2 class="show-anchors"><div>Node-Specific Methods<div class="anchors"><a class="self" href="/v5/api/providers/jsonrpc-provider/#JsonRpcProvider--other"></a></div></div></h2><p>Many methods are less common or specific to certain Ethereum Node implementations (e.g. <a href="https://www.parity.io">Parity</a> vs <a href="https://geth.ethereum.org">Geth</a>. These include account and admin management, debugging, deeper block and transaction exploration and other services (such as Swarm and Whisper).</p>
<p>The <a href="/v5/api/providers/jsonrpc-provider/#JsonRpcProvider-send">jsonRpcProvider.send</a> method can be used to access these.</p>
<p><ul><li><a href="https://github.com/ethereum/wiki/wiki/JSON-RPC">All JSON-RPC methods</a> (including the less common methods) which most Ethereum Nodes support. </li><li><a href="https://openethereum.github.io/wiki/JSONRPC-trace-module">Parity's Trace Module</a> can be used to trace and debug EVM execution of a transaction (requires custom configuration) </li><li><a href="https://github.com/ethereum/go-ethereum/wiki/Management-APIs#debug">Geth's Debug Module</a> can be used to debug transactions and internal cache state, etc. </li><li><a href="https://github.com/ethereum/go-ethereum/wiki/Management-APIs">Additional Geth Methods</a> </li><li><a href="https://openethereum.github.io/wiki/JSONRPC">Additional Parity Methods</a> </li></ul></p>
<div class="footer">
<div class="nav previous"><a href="/v5/api/providers/provider/"><span class="arrow">&larr;</span>Provider</a></div>
<div class="nav next"><a href="/v5/api/providers/api-providers/">API Providers<span class="arrow">&rarr;</span></a></div>
</div>
<div class="copyright">The content of this site is licensed under the <a href="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Generated on July 3, 2020, 1:44am.</div>
</div>
<script src="/v5/static/script.js" type="text/javascript"></script>
</body>
</html>