89 lines
19 KiB
HTML
89 lines
19 KiB
HTML
<!DOCTYPE html>
|
|
<html class="paged">
|
|
<head>
|
|
<title>Transactions</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 show link depth-1"><a href="/v5/api-keys/">Provider API Keys</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/providers/">Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/provider/">Provider</a></div><div class="hide link depth-3"><a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><div class="hide link depth-3"><a href="/v5/api/providers/api-providers/">API Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/other/">Other Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/types/">Types</a></div><div class="show link depth-2"><a href="/v5/api/signer/">Signers</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="ancestor show link depth-2"><a href="/v5/api/utils/">Utilities</a></div><div class="show 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="show link depth-3"><a href="/v5/api/utils/address/">Addresses</a></div><div class="show link depth-3"><a href="/v5/api/utils/bignumber/">BigNumber</a></div><div class="show link depth-3"><a href="/v5/api/utils/bytes/">Byte Manipulation</a></div><div class="show link depth-3"><a href="/v5/api/utils/constants/">Constants</a></div><div class="show link depth-3"><a href="/v5/api/utils/display-logic/">Display Logic and Input</a></div><div class="show link depth-3"><a href="/v5/api/utils/encoding/">Encoding Utilities</a></div><div class="show link depth-3"><a href="/v5/api/utils/fixednumber/">FixedNumber</a></div><div class="show link depth-3"><a href="/v5/api/utils/hashing/">Hashing Algorithms</a></div><div class="show link depth-3"><a href="/v5/api/utils/hdnode/">HD Wallet</a></div><div class="show link depth-3"><a href="/v5/api/utils/logger/">Logging</a></div><div class="show link depth-3"><a href="/v5/api/utils/properties/">Property Utilities</a></div><div class="show link depth-3"><a href="/v5/api/utils/signing-key/">Signing Key</a></div><div class="show link depth-3"><a href="/v5/api/utils/strings/">Strings</a></div><div class="myself ancestor ancestor show link depth-3"><a href="/v5/api/utils/transactions/">Transactions</a></div><div class="show link depth-3"><a href="/v5/api/utils/web/">Web Utilities</a></div><div class="show 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="hide link depth-2"><a href="/v5/cookbook/react-native/">React Native (and ilk)</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> » <a href="/v5/api/">API</a> » <a href="/v5/api/utils/">Utilities</a> » <span class="current">Transactions</span></div>
|
|
|
|
<a name="transactions"></a><a name="transactions"></a><h1 class="show-anchors"><div>Transactions<div class="anchors"><a class="self" href="/v5/api/utils/transactions/#transactions"></a></div></div></h1>
|
|
<a name="transactions--types"></a><a name="transactions--transactions--types"></a><h2 class="show-anchors"><div>Types<div class="anchors"><a class="self" href="/v5/api/utils/transactions/#transactions--types"></a></div></div></h2>
|
|
<a name="UnsignedTransaction"></a><a name="transactions--transactions--types--UnsignedTransaction"></a><h3 class="show-anchors"><div>UnsignedTransaction<div class="anchors"><a class="self" href="/v5/api/utils/transactions/#UnsignedTransaction"></a></div></div></h3><p>An unsigned transaction represents a transaction that has not been signed and its values are flexible as long as they are not ambiguous.</p>
|
|
|
|
<div class="property show-anchors"><div class="signature"><span class="path">unsignedTransaction</span><span class="symbol">.</span><span class="method">to</span> <span class="arrow">⇒</span> <span class="returns">string< <a href="/v5/api/utils/address/#address">Address</a> ></span><div class="anchors"></div></div><div class="body"><p>The addres this transaction is to.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">unsignedTransaction</span><span class="symbol">.</span><span class="method">nonce</span> <span class="arrow">⇒</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The nonce of this transaction.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">unsignedTransaction</span><span class="symbol">.</span><span class="method">gasLimit</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/utils/bignumber/#BigNumberish">BigNumberish</a></span><div class="anchors"></div></div><div class="body"><p>The gas limit for this transaction.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">unsignedTransaction</span><span class="symbol">.</span><span class="method">gasPrice</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/utils/bignumber/#BigNumberish">BigNumberish</a></span><div class="anchors"></div></div><div class="body"><p>The gas price for this transaction.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">unsignedTransaction</span><span class="symbol">.</span><span class="method">data</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/utils/bytes/#BytesLike">BytesLike</a></span><div class="anchors"></div></div><div class="body"><p>The data for this transaction.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">unsignedTransaction</span><span class="symbol">.</span><span class="method">value</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/utils/bignumber/#BigNumberish">BigNumberish</a></span><div class="anchors"></div></div><div class="body"><p>The value (in wei) for this transaction.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">unsignedTransaction</span><span class="symbol">.</span><span class="method">chainId</span> <span class="arrow">⇒</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The chain ID for this transaction. If the chain ID is 0 or null, then <a href="https://eips.ethereum.org/EIPS/eip-155">EIP-155</a> is disabled and legacy signing is used, unless overridden in a signature.</p>
|
|
|
|
</div></div><a name="Transaction"></a><a name="transactions--transactions--types--Transaction"></a><h3 class="show-anchors"><div>Transaction<div class="anchors"><a class="self" href="/v5/api/utils/transactions/#Transaction"></a></div></div></h3><p>A generic object to represent a transaction.</p>
|
|
|
|
<div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">hash</span> <span class="arrow">⇒</span> <span class="returns">string< <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 > ></span><div class="anchors"></div></div><div class="body"><p>The transaction hash, which can be used as an identifier for <i>transaction</i>. This is the keccak256 of the serialized RLP encoded representation of <i>transaction</i>.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">unsignedTransaction</span><span class="symbol">.</span><span class="method">to</span> <span class="arrow">⇒</span> <span class="returns">string< <a href="/v5/api/utils/address/#address">Address</a> ></span><div class="anchors"></div></div><div class="body"><p>The address <i>transaction</i> is to.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">from</span> <span class="arrow">⇒</span> <span class="returns">string< <a href="/v5/api/utils/address/#address">Address</a> ></span><div class="anchors"></div></div><div class="body"><p>The address <i>transaction</i> is from.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">nonce</span> <span class="arrow">⇒</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The nonce for <i>transaction</i>. Each transaction sent to the network from an account includes this, which ensures the order and non-replayability of a transaction. This must be equal to the current number of transactions ever sent to the network by the <b>from</b> address.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">gasLimit</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/utils/bignumber/">BigNumber</a></span><div class="anchors"></div></div><div class="body"><p>The gas limit for <i>transaction</i>. An account must have enough ether to cover the gas (at the specified <b>gasPrice</b>). Any unused gas is refunded at the end of the transaction, and if there is insufficient gas to complete execution, the effects of the trasaction are reverted, but the gas is <b>fully consumed</b> and an out-of-gas error occurs.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">gasPrice</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/utils/bignumber/">BigNumber</a></span><div class="anchors"></div></div><div class="body"><p>The price (in wei) per unit of gas for <i>transaction</i>.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">data</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/utils/bytes/#BytesLike">BytesLike</a></span><div class="anchors"></div></div><div class="body"><p>The data for <i>transaction</i>. In a contract this is the call data.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">value</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/utils/bignumber/">BigNumber</a></span><div class="anchors"></div></div><div class="body"><p>The value (in wei) for <i>transaction</i>.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">chainId</span> <span class="arrow">⇒</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The chain ID for <i>transaction</i>. This is used as part of <a href="https://eips.ethereum.org/EIPS/eip-155">EIP-155</a> to prevent replay attacks on different networks.</p>
|
|
|
|
<p>For example, if a transaction was made on ropsten with an account also used on homestead, it would be possible for a transaction signed on ropsten to be executed on homestead, which is likely unintended.</p>
|
|
|
|
<p>There are situations where replay may be desired, however these are very rare and it is almost always recommended to specify the chain ID.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">r</span> <span class="arrow">⇒</span> <span class="returns">string< <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 > ></span><div class="anchors"></div></div><div class="body"><p>The r portion of the elliptic curve signatures for <i>transaction</i>. This is more accurately, the x coordinate of the point r (from which the y can be computed, along with v).</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">s</span> <span class="arrow">⇒</span> <span class="returns">string< <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 > ></span><div class="anchors"></div></div><div class="body"><p>The s portion of the elliptic curve signatures for <i>transaction</i>.</p>
|
|
|
|
</div></div><div class="property show-anchors"><div class="signature"><span class="path">transaction</span><span class="symbol">.</span><span class="method">v</span> <span class="arrow">⇒</span> <span class="returns">number</span><div class="anchors"></div></div><div class="body"><p>The v portion of the elliptic curve signatures for <i>transaction</i>. This is used to refine which of the two possible points a given x-coordinate can have, and in <a href="https://eips.ethereum.org/EIPS/eip-155">EIP-155</a> is additionally used to encode the chain ID into the serialized transaction.</p>
|
|
|
|
</div></div><a name="transactions--functions"></a><a name="transactions--transactions--functions"></a><h2 class="show-anchors"><div>Functions<div class="anchors"><a class="self" href="/v5/api/utils/transactions/#transactions--functions"></a></div></div></h2>
|
|
<a name="utils-parseTransaction"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">parseTransaction</span><span class="symbol">(</span> <span class="param">aBytesLike</span> <span class="symbol">)</span> <span class="arrow">⇒</span> <span class="returns"><a href="/v5/api/utils/transactions/#Transaction">Transaction</a></span><div class="anchors"><a class="self" href="/v5/api/utils/transactions/#utils-parseTransaction"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/transactions/src.ts/index.ts#L165">source</a></div></div><div class="body"><p>Parses the transaction properties from a serialized transactions.</p>
|
|
|
|
</div></div><a name="utils-serializeTransaction"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">serializeTransaction</span><span class="symbol">(</span> <span class="param">tx</span> <span class="symbol">[</span> <span class="symbol">,</span> <span class="param">signature</span> <span class="symbol">]</span> <span class="symbol">)</span> <span class="arrow">⇒</span> <span class="returns">string< <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a> ></span><div class="anchors"><a class="self" href="/v5/api/utils/transactions/#utils-serializeTransaction"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/master/packages/transactions/src.ts/index.ts#L85">source</a></div></div><div class="body"><p>Computes the serialized <i>transaction</i>, optionally serialized with the a <i>signature</i>. If <i>signature</i> is not present, the unsigned serialized transaction is returned, which can be used to compute the hash necessary to sign.</p>
|
|
|
|
<p>This function uses <a href="https://eips.ethereum.org/EIPS/eip-155">EIP-155</a> if a chainId is provided, otherwise legacy serialization is used. It is <b>highly</b> recommended to always specify a <i>chainId</i>.</p>
|
|
|
|
<p>If <i>signature</i> includes a chain ID (explicitly or implicitly by using an <a href="https://eips.ethereum.org/EIPS/eip-155">EIP-155</a> <code class="inline">v</code> or <code class="inline">_vs</code>) it will be used to compute the chain ID.</p>
|
|
|
|
<p>If there is a mismatch between the chain ID of <i>transaction</i> and <i>signature</i> an error is thrown.</p>
|
|
|
|
</div></div>
|
|
|
|
<div class="footer">
|
|
<div class="nav previous"><a href="/v5/api/utils/strings/"><span class="arrow">←</span>Strings</a></div>
|
|
<div class="nav next"><a href="/v5/api/utils/web/">Web Utilities<span class="arrow">→</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 September 8, 2020, 1:8am.</div>
|
|
</div>
|
|
<script src="/v5/static/script.js" type="text/javascript"></script>
|
|
</body>
|
|
</html>
|