45 lines
25 KiB
HTML
45 lines
25 KiB
HTML
|
<html><head><title>ethers v4 to v5</title><link rel="stylesheet" type="text/css" href="/static/style.css"></head><body><div class="sidebar"><div class="header"><div class="logo"><a href="/"><div class="image"></div><div class="name">ethers</div><div class="version">v5.0-beta</div></a></div></div><div class="toc"><div><div class="link title"><a href="/">Documentation</a></div><div class="base show link depth-1"><a href="/getting-started/">Getting Started</a></div><div class="hide link depth-2"><a href="/getting-started/#installing">Installing</a></div><div class="hide link depth-2"><a href="/getting-started/#importing">Importing</a></div><div class="base show link depth-1"><a href="/concepts/">Concepts</a></div><div class="hide link depth-2"><a href="/concepts/events/">Events</a></div><div class="hide link depth-3"><a href="/concepts/events/#solidity-topics">Solidity Topics</a></div><div class="hide link depth-2"><a href="/concepts/gas/">Gas</a></div><div class="hide link depth-3"><a href="/concepts/gas/#gas-price">Gas Price</a></div><div class="hide link depth-3"><a href="/concepts/gas/#gas-limit">Gas Limit</a></div><div class="base show link depth-1"><a href="/api/">Application Programming Interface</a></div><div class="hide link depth-2"><a href="/api/contract/">Contracts</a></div><div class="hide link depth-3"><a href="/api/contract/#buckets">Buckets</a></div><div class="hide link depth-2"><a href="/api/signer/">Signers</a></div><div class="hide link depth-3"><a href="/api/signer/#signer">Signer</a></div><div class="hide link depth-3"><a href="/api/signer/#wallet">Wallet</a></div><div class="hide link depth-3"><a href="/api/signer/#voidsigner">VoidSigner</a></div><div class="hide link depth-3"><a href="/api/signer/#externallyownedaccount">ExternallyOwnedAccount</a></div><div class="hide link depth-2"><a href="/api/providers/">Providers</a></div><div class="hide link depth-3"><a href="/api/providers/provider/">Provider</a></div><div class="hide link depth-4"><a href="/api/providers/provider/#accounts-methods">Accounts Methods</a></div><div class="hide link depth-4"><a href="/api/providers/provider/#blocks-methods">Blocks Methods</a></div><div class="hide link depth-4"><a href="/api/providers/provider/#ethereum-naming-service-(ens)-methods">Ethereum Naming Service (ENS) Methods</a></div><div class="hide link depth-4"><a href="/api/providers/provider/#logs-methods">Logs Methods</a></div><div class="hide link depth-4"><a href="/api/providers/provider/#network-status-methods">Network Status Methods</a></div><div class="hide link depth-4"><a href="/api/providers/provider/#transactions-methods">Transactions Methods</a></div><div class="hide link depth-4"><a href="/api/providers/provider/#event-emitter-methods">Event Emitter Methods</a></div><div class="hide link depth-4"><a href="/api/providers/provider/#inspection-methods">Inspection Methods</a></div><div class="hide link depth-3"><a href="/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><div class="hide link depth-4"><a href="/api/providers/jsonrpc-provider/#jsonrpcsigner">JsonRpcSigner</a></div><div class="hide link depth-4"><a href="/api/providers/jsonrpc-provider/#jsonrpcuncheckedsigner">JsonRpcUncheckedSigner</a></div><div class="hide link depth-3"><a href="/api/providers/api-providers/">API Providers</a></div><div class="hide link depth-4"><a href="/api/providers/api-providers/#etherscanprovider">EtherscanProvider</a></div><div class="hide link depth-4"><a href="/api/providers/api-providers/#infuraprovider">InfuraProvider</a></div><div class="hide link depth-4"><a href="/api/providers/api-providers/#alchemyprovider">AlchemyProvider</a></div><div class="hide link depth-4"><a href="/api/providers/api-providers/#cloudfrontprovider">CloudfrontProvider</a></div><div class="hide link depth-3"><a href="/api/providers/other/">Other Providers</a></div><div class="hide link depth-4"><a href="/api/providers/other/#fallbackprovider">FallbackProvider</a></div><div class="hide link depth-4"><a href="/api/providers/other/#ipcprovider">IpcProvider</a></div><div class="hide
|
||
|
<a name="migration:-from-ethers-v4"></a><h1 class="show-anchors"><div>Migration: From Ethers v4<div class="anchors"><a class="self" href="#migration:-from-ethers-v4"></a></div></div></h1>
|
||
|
|
||
|
<a name="bignumber"></a><h2 class="show-anchors"><div>BigNumber<div class="anchors"><a class="self" href="#bignumber"></a></div></div></h2>
|
||
|
|
||
|
<a name="namespace"></a><h3 class="show-anchors"><div>Namespace<div class="anchors"><a class="self" href="#namespace"></a></div></div></h3>
|
||
|
<p>Since <a href="/api/utils/bignumber/">BigNumber</a> is used quite frequently, it has been moved to the top level of the umbrella package.</p>
|
||
|
<div class="code">// v4<br>ethers.utils.BigNumber<br>ethers.utils.BigNumberish<br><br>// v5<br>ethers.BigNumber<br>ethers.BigNumberish</div>
|
||
|
|
||
|
<a name="creating-instances"></a><h3 class="show-anchors"><div>Creating Instances<div class="anchors"><a class="self" href="#creating-instances"></a></div></div></h3>
|
||
|
<p>The <code class="inline">bigNumberify</code> method was always preferred over the constructor since it could short-circuit an object instantiation for [[bignumber] objects (since they are immutable). This has been moved to a static <code class="inline">from</code> class method.</p>
|
||
|
<div class="code">// v4<br>new ethers.utils.BigNumber(someValue)<br>ethers.utils.bigNumberify(someValue);<br><br>// v5<br>// - Constructor is private<br>// - Removed `bigNumberify`<br>ethers.BigNumber.from(someValue)</div>
|
||
|
|
||
|
<a name="contracts"></a><h2 class="show-anchors"><div>Contracts<div class="anchors"><a class="self" href="#contracts"></a></div></div></h2>
|
||
|
<div class="code">TODO</div>
|
||
|
|
||
|
<a name="errors"></a><h2 class="show-anchors"><div>Errors<div class="anchors"><a class="self" href="#errors"></a></div></div></h2>
|
||
|
|
||
|
<a name="namespace"></a><h3 class="show-anchors"><div>Namespace<div class="anchors"><a class="self" href="#namespace"></a></div></div></h3>
|
||
|
<p>All errors now belong to the <a href="/api/utils/logger/">Logger</a> class and the related functions have been moved to <a href="/api/utils/logger/">Logger</a> instances, which can include a per-package version string.</p><p>Global error fucntions have been moved <a href="/api/utils/logger/">Logger</a> class methods.</p>
|
||
|
<div class="code">// v4<br>ethers.errors.UNKNOWN_ERROR<br>ethers.errors.*<br><br>errors.setCensorship(censorship, permanent)<br>errors.setLogLevel(logLevel)<br><br>errors.checkArgumentCount(count, expectedCount, suffix)<br>errors.checkNew(self, kind)<br>errors.checkNormalize()<br>errors.throwError(message, code, params)<br>errors.warn(...)<br>errors.info(...)<br><br>// v5<br>ethers.utils.Logger.errors.UNKNOWN_ERROR<br>ethers.utils.Logger.errors.*<br><br>Logger.setCensorship(censorship, permanent)<br>Logger.setLogLevel(logLevel)<br><br>const logger = new ethers.utils.Logger(version);<br>logger.checkArgumentCount(count, expectedCount, suffix)<br>logger.checkNew(self, kind)<br>logger.checkNormalize()<br>logger.throwError(message, code, params)<br>logger.warn(...)<br>logger.info(...)</div>
|
||
|
|
||
|
<a name="interface"></a><h2 class="show-anchors"><div>Interface<div class="anchors"><a class="self" href="#interface"></a></div></div></h2>
|
||
|
<p>The <a href="/api/utils/abi/#abi-interface">Interface</a> object has undergone the most dramatic changes.</p><p>It is no longer a meta-class and now has methods that simplify handling contract interface operations without the need for object inspection and special edge cases.</p>
|
||
|
<a name="functions"></a><h3 class="show-anchors"><div>Functions<div class="anchors"><a class="self" href="#functions"></a></div></div></h3>
|
||
|
<div class="code">// v4 (example: "transfer(address to, uint amount)")<br>interface.functions.transfer.encode(to, amount)<br>interface.functions.transfer.decode(callData)<br><br>// v5<br>interface.encodeData("transfer", [ to, amount ])<br>interface.decodeResult("transfer", data)<br><br>// Or you can use any compatible signature or Fragment objects.<br>// Notice that signature normalization is performed for you,<br>// e.g. "uint" and "uint256" will be automatically converted<br>interface.encodeData("transfer(address,uint)", [ to, amount ])<br>interface.decodeResult("transfer(address to, uint256 amount)", data)</div>
|
||
|
|
||
|
<a name="events"></a><h3 class="show-anchors"><div>Events<div class="anchors"><a class="self" href="#events"></a></div></div></h3>
|
||
|
<div class="code">// v4 (example: Transfer(address indexed, address indexed, uint256)<br>interface.events.Transfer.encodeTopics(values)<br>interface.events.Transfer.decode(data, topics)<br><br>// v5<br>interface.encodeFilterTopics("Transfer", values)<br>interface.encodeEventLog("Transfer", data, topics)</div>
|
||
|
|
||
|
<a name="inspection"></a><h3 class="show-anchors"><div>Inspection<div class="anchors"><a class="self" href="#inspection"></a></div></div></h3>
|
||
|
<p>Interrogating properties about a function or event can now (mostly) be done directly on the <a href="/api/utils/abi/#abi-fragment">Fragment</a> object.</p>
|
||
|
<div class="code">// v4<br>interface.functions.transfer.name<br>interface.functions.transfer.inputs<br>interface.functions.transfer.outputs<br>interface.functions.transfer.payable<br>interface.functions.transfer.gas<br><br>// v5<br>const functionFragment = interface.getFunction("transfer")<br>functionFragment.name<br>functionFragment.inputs<br>functionFragment.outputs<br>functionFragment.payable<br>functionFragment.gas<br><br><br>// v4; type is "call" or "transaction"<br>interface.functions.transfer.type<br><br>// v5; constant is true (i.e. "call") or false (i.e. "transaction")<br>functionFragment.constant<br><br><br>// v4<br>interface.events.Transfer.anonymous<br>interface.events.Transfer.inputs<br>interface.events.Transfer.name<br><br>// v5<br>const eventFragment = interface.getEvent("Transfer");<br>eventFragment.anonymous<br>eventFragment.inputs<br>eventFragment.name<br><br><br>// v4<br>const functionSig = interface.functions.transfer.signature<br>const sighash = interface.functions.transfer.sighash<br><br>const eventSig = interface.events.Transfer.signature<br>const topic = interface.events.Transfer.topic<br><br>// v5<br>const functionSig = functionFragment.format()<br>const sighash = interface.getSighash(functionFragment)<br><br>const eventSig = eventFragment.format()<br>const topic = interface.getTopic(eventFragment)</div>
|
||
|
|
||
|
<a name="utilities"></a><h2 class="show-anchors"><div>Utilities<div class="anchors"><a class="self" href="#utilities"></a></div></div></h2>
|
||
|
|
||
|
<a name="renaming"></a><h3 class="show-anchors"><div>Renaming<div class="anchors"><a class="self" href="#renaming"></a></div></div></h3>
|
||
|
<div class="code">TODO</div>
|
||
|
|
||
|
<a name="wallet"></a><h2 class="show-anchors"><div>Wallet<div class="anchors"><a class="self" href="#wallet"></a></div></div></h2>
|
||
|
|
||
|
<a name="mnemonic-phrases"></a><h3 class="show-anchors"><div>Mnemonic Phrases<div class="anchors"><a class="self" href="#mnemonic-phrases"></a></div></div></h3>
|
||
|
<p>The <b>mnemonic</b> phrase and related properties have been merged into a single <code class="inline">mnemonic</code> object, which also now includes the <code class="inline">locale</code>.</p>
|
||
|
<div class="code">// v4<br>wallet.mnemonic<br>wallet.path<br><br>// v5<br>// - Mnemonic phrase and path are a Mnemonic object<br>// - Note: wallet.mnemonic is null if there is no mnemonic<br>wallet.mnemonic.phrase<br>wallet.mnemonic.path</div>
|
||
|
<div class="footer"><div class="nav previous"><a href="/migration/web3/"><span class="arrow">←</span>Migration: From Web3.js</a></div> <div class="nav next"><a href="/testing/">Testing<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 Attribution 4.0 International License</a>.</div></div><script src="/script.js" type="text/javascript"></script></body></html><!-- ContentHash:b23835fe0ae8cb86b0b5436e141e68656882e8754a899c46078964b042ed6ef3 -->
|