<divclass="link title"><ahref="/v5/">Documentation</a></div><divclass="base show link depth-1"><ahref="/v5/getting-started/">Getting Started</a></div><divclass="base show link depth-1"><ahref="/v5/concepts/">Ethereum Basics</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/events/">Events</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/gas/">Gas</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/security/">Security</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/best-practices/">Best Practices</a></div><divclass="base show link depth-1"><ahref="/v5/api-keys/">Provider API Keys</a></div><divclass="base ancestor show link depth-1"><ahref="/v5/api/">Application Programming Interface</a></div><divclass="show link depth-2"><ahref="/v5/api/providers/">Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/provider/">Provider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/api-providers/">API Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/other/">Other Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/types/">Types</a></div><divclass="show link depth-2"><ahref="/v5/api/signer/">Signers</a></div><divclass="show link depth-2"><ahref="/v5/api/contract/">Contract Interaction</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract/">Contract</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract-factory/">ContractFactory</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><divclass="ancestor show link depth-2"><ahref="/v5/api/utils/">Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/abi/">Application Binary Interface</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/coder/">AbiCoder</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/formats/">ABI Formats</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/fragments/">Fragments</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/interface/">Interface</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/address/">Addresses</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/bignumber/">BigNumber</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/bytes/">Byte Manipulation</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/constants/">Constants</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/display-logic/">Display Logic and Input</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/encoding/">Encoding Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/fixednumber/">FixedNumber</a></div><divclass="myself ancestor ancestor show link depth-3"><ahref="/v5/api/utils/hashing/">Hashing Algorithms</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/hdnode/">HD Wallet</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/logger/">Logging</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/properties/">Property Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/signing-key/">Signing Key</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/strings/">Strings</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/transactions/">Transactions</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/web/">Web Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/wordlists/">Wordlists</a></div><divclass="show link depth-2"><ahref="/v5/api/other/">Other Libraries</a></div><divclass="hide link depth-3"><ahref="/v5/api/other/assembly/">Assembly</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/api/">Utilities</a></div><divclass="hidelinkde
<aname="hashing-algorithms"></a><aname="hashing-algorithms"></a><h1class="show-anchors"><div>Hashing Algorithms<divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#hashing-algorithms"></a></div></div></h1><p>There are many hashing algorithms used throughout the blockchain space as well as some more complex usages which require utilities to facilitate these common operations.</p>
<aname="cryptographic-hash-functions"></a><aname="hashing-algorithms--cryptographic-hash-functions"></a><h2class="show-anchors"><div>Cryptographic Hash Functions<divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#cryptographic-hash-functions"></a></div></div></h2><p>The <ahref="https://en.wikipedia.org/wiki/Cryptographic_hash_function">Cryptographic Hash Functions</a> are a specific family of hash functions.</p>
<aname="utils-id"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">id</span><spanclass="symbol">(</span><spanclass="param">text</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 >></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils-id"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/id.ts#L4">source</a></div></div><divclass="body"><p>The Ethereum Identity function computes the <ahref="https://en.wikipedia.org/wiki/SHA-3">KECCAK256</a> hash of the <i>text</i> bytes.</p>
</div></div><aname="utils-ripemd160"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">ripemd160</span><spanclass="symbol">(</span><spanclass="param">aBytesLike</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 20 >></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils-ripemd160"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/sha2/src.ts/sha2.ts#L13">source</a></div></div><divclass="body"><p>Returns the <ahref="https://en.m.wikipedia.org/wiki/RIPEMD">RIPEMD-160</a> digest of <i>aBytesLike</i>.</p>
</div></div><aname="utils-sha256"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">sha256</span><spanclass="symbol">(</span><spanclass="param">aBytesLike</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 >></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils-sha256"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/sha2/src.ts/sha2.ts#L17">source</a></div></div><divclass="body"><p>Returns the <ahref="https://en.wikipedia.org/wiki/SHA-2">SHA2-256</a> digest of <i>aBytesLike</i>.</p>
</div></div><aname="utils-sha512"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">sha512</span><spanclass="symbol">(</span><spanclass="param">aBytesLike</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 64 >></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils-sha512"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/sha2/src.ts/sha2.ts#L21">source</a></div></div><divclass="body"><p>Returns the <ahref="https://en.wikipedia.org/wiki/SHA-2">SHA2-512</a> digest of <i>aBytesLike</i>.</p>
<aname="utils-computeHmac"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">computeHmac</span><spanclass="symbol">(</span><spanclass="param">algorithm</span><spanclass="symbol">,</span><spanclass="param">key</span><spanclass="symbol">,</span><spanclass="param">data</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils-computeHmac"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/sha2/src.ts/sha2.ts#L25">source</a></div></div><divclass="body"><p>Returns the <ahref="https://en.wikipedia.org/wiki/HMAC">HMAC</a> of <i>data</i> with <i>key</i> using the <ahref="/v5/api/utils/hashing/#utils--hmac-supported-algorithm">Algorithm</a><i>algorithm</i>.</p>
<aname="utils-hashMessage"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">hashMessage</span><spanclass="symbol">(</span><spanclass="param">message</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 >></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils-hashMessage"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/message.ts#L7">source</a></div></div><divclass="body"><p>Computes the <ahref="https://eips.ethereum.org/EIPS/eip-191">EIP-191</a> personal message digest of <i>message</i>. Personal messages are converted to UTF-8 bytes and prefixed with <codeclass="inline">\x19Ethereum Signed Message:</code> and the length of <i>message</i>.</p>
</span></div><aname="utils-namehash"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">namehash</span><spanclass="symbol">(</span><spanclass="param">name</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 >></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils-namehash"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/namehash.ts#L27">source</a></div></div><divclass="body"><p>Returns the <ahref="https://docs.ens.domains/contract-api-reference/name-processing#hashing-names">ENS Namehash</a> of <i>name</i>.</p>
</span></div><aname="TypedDataEncoder"></a><aname="hashing-algorithms--utils--hashing-helpers--TypedDataEncoder"></a><h3class="show-anchors"><div>Typed Data Encoder<divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#TypedDataEncoder"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/typed-data.ts#L148">source</a></div></div></h3><p>The <b>TypedDataEncoder</b> is used to compute the various encoded data required for <ahref="https://eips.ethereum.org/EIPS/eip-712">EIP-712</a> signed data.</p>
<p>Signed data requires a domain, list of structures and their members and the data itself.</p>
<p>The <b>domain</b> is an object with values for any of the standard domain properties.</p>
<p>The <b>types</b> is an object with each property being the name of a structure, mapping to an array of field descriptions. It should <b>not</b> include the <codeclass="inline">EIP712Domain</code> property unless it is required as a child structure of another.</p>
<divclass="definition container-box note"><divclass="term">Experimental Feature (this exported class name will change)</div><divclass="body"><p>This is still an experimental feature. If using it, please specify the <b>exact</b> version of ethers you are using (e.g. spcify <codeclass="inline">"5.0.18"</code>, <b>not</b><codeclass="inline">"^5.0.18"</code>) as the exported class name will be renamed from <codeclass="inline">_TypedDataEncoder</code> to <codeclass="inline">TypedDataEncoder</code> once it has been used in the field a bit.</p>
</div></div><aname="TypedDataEncoder-from"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="path">_TypedDataEncoder</span><spanclass="symbol">.</span><spanclass="method">from</span><spanclass="symbol">(</span><spanclass="param">types</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">[TypedDataEncoder]</span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#TypedDataEncoder-from"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/typed-data.ts#L363">source</a></div></div><divclass="body"><p>Creates a new <b>TypedDataEncoder</b> for <i>types</i>. This object is a fairly low-level object that most developers should not require using instances directly.</p>
<p>Most developers will find the static class methods below the most useful.</p>
</div></div><aname="TypedDataEncoder-encode"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">TypedDataEncoder</span><spanclass="symbol">.</span><spanclass="method">encode</span><spanclass="symbol">(</span><spanclass="param">domain</span><spanclass="symbol">,</span><spanclass="param">types</span><spanclass="symbol">,</span><spanclass="param">values</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string</span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#TypedDataEncoder-encode"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/typed-data.ts#L392">source</a></div></div><divclass="body"><p>Encodes the Returns the hashed <ahref="https://eips.ethereum.org/EIPS/eip-712">EIP-712</a> domain.</p>
</div></div><aname="TypedDataEncoder-getPayload"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">TypedDataEncoder</span><spanclass="symbol">.</span><spanclass="method">getPayload</span><spanclass="symbol">(</span><spanclass="param">domain</span><spanclass="symbol">,</span><spanclass="param">types</span><spanclass="symbol">,</span><spanclass="param">value</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">any</span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#TypedDataEncoder-getPayload"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/typed-data.ts#L447">source</a></div></div><divclass="body"><p>Returns the standard payload used by various JSON-RPC <codeclass="inline">eth_signTypedData*</code> calls.</p>
<p>All domain values and entries in value are normalized and the types are verified.</p>
</div></div><aname="TypedDataEncoder-getPrimaryType"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">TypedDataEncoder</span><spanclass="symbol">.</span><spanclass="method">getPrimaryType</span><spanclass="symbol">(</span><spanclass="param">types</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string</span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#TypedDataEncoder-getPrimaryType"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/typed-data.ts#L367">source</a></div></div><divclass="body"><p>Constructs a directed acyclic graph of the types and returns the root type, which can be used as the <b>primaryType</b> for <ahref="https://eips.ethereum.org/EIPS/eip-712">EIP-712</a> payloads.</p>
</div></div><aname="TypedDataEncoder-hash"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">TypedDataEncoder</span><spanclass="symbol">.</span><spanclass="method">hash</span><spanclass="symbol">(</span><spanclass="param">domain</span><spanclass="symbol">,</span><spanclass="param">types</span><spanclass="symbol">,</span><spanclass="param">values</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 >></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#TypedDataEncoder-hash"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/typed-data.ts#L400">source</a></div></div><divclass="body"><p>Returns the computed <ahref="https://eips.ethereum.org/EIPS/eip-712">EIP-712</a> hash.</p>
</div></div><aname="TypedDataEncoder-hashDomain"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">TypedDataEncoder</span><spanclass="symbol">.</span><spanclass="method">hashDomain</span><spanclass="symbol">(</span><spanclass="param">domain</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 >></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#TypedDataEncoder-hashDomain"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/typed-data.ts#L375">source</a></div></div><divclass="body"><p>Returns the hashed <ahref="https://eips.ethereum.org/EIPS/eip-712">EIP-712</a> domain.</p>
</div></div><aname="TypedDataEncoder-resolveNames"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">TypedDataEncoder</span><spanclass="symbol">.</span><spanclass="method">resolveNames</span><spanclass="symbol">(</span><spanclass="param">domain</span><spanclass="symbol">,</span><spanclass="param">types</span><spanclass="symbol">,</span><spanclass="param">value</span><spanclass="symbol">,</span><spanclass="param">resolveName</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">Promise< any ></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#TypedDataEncoder-resolveNames"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/hash/src.ts/typed-data.ts#L405">source</a></div></div><divclass="body"><p>Returns a copy of value, where any leaf value with a type of <codeclass="inline">address</code> will have been recursively replacedwith the value of calling <i>resolveName</i> with that value.</p>
</div></div><divclass="code-title"><div>Typed Data Example</div></div><divclass="code">const domain = {
</span></div><aname="utils--solidity-hashing"></a><aname="hashing-algorithms--utils--solidity-hashing"></a><h2class="show-anchors"><div>Solidity Hashing Algorithms<divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils--solidity-hashing"></a></div></div></h2><p>When using the Solidity <codeclass="inline">abi.packEncoded(...)</code> function, a non-standard <i>tightly packed</i> version of encoding is used. These functions implement the tightly packing algorithm.</p>
<aname="utils-solidityPack"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">solidityPack</span><spanclass="symbol">(</span><spanclass="param">types</span><spanclass="symbol">,</span><spanclass="param">values</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils-solidityPack"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/solidity/src.ts/index.ts#L75">source</a></div></div><divclass="body"><p>Returns the non-standard encoded <i>values</i> packed according to their respective type in <i>types</i>.</p>
</div></div><aname="utils-solidityKeccak256"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">solidityKeccak256</span><spanclass="symbol">(</span><spanclass="param">types</span><spanclass="symbol">,</span><spanclass="param">values</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 >></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils-solidityKeccak256"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/solidity/src.ts/index.ts#L84">source</a></div></div><divclass="body"><p>Returns the <ahref="https://en.wikipedia.org/wiki/SHA-3">KECCAK256</a> of the non-standard encoded <i>values</i> packed according to their respective type in <i>types</i>.</p>
</div></div><aname="utils-soliditySha256"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">soliditySha256</span><spanclass="symbol">(</span><spanclass="param">types</span><spanclass="symbol">,</span><spanclass="param">values</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string<<ahref="/v5/api/utils/bytes/#DataHexString">DataHexString</a>< 32 >></span><divclass="anchors"><aclass="self"href="/v5/api/utils/hashing/#utils-soliditySha256"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/solidity/src.ts/index.ts#L88">source</a></div></div><divclass="body"><p>Returns the <ahref="https://en.wikipedia.org/wiki/SHA-2">SHA2-256</a> of the non-standard encoded <i>values</i> packed according to their respective type in <i>types</i>.</p>
<divclass="copyright">The content of this site is licensed under the <ahref="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Generated on November 22, 2020, 11:5pm.</div>