<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="base ancestor show link depth-1"><ahref="/v5/api/">Application Programming Interface</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="show link depth-2"><ahref="/v5/api/signer/">Signers</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="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="hide link depth-4"><ahref="/v5/api/other/assembly/ast/">Abstract Syntax Tree</a></div><divclass="hide link depth-3"><ahref="/v5/api/other/hardware/">Hardware Wallets</a></div><divclass="sho
<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>Explain what hash functions are?</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/ethers-v5-beta/packages/hash/src.ts/index.ts#L47">source</a></div></div><divclass="body"><p>The Ethereum Identity function computs the <ahref="https://en.wikipedia.org/wiki/SHA-3">KECCAK256</a> hash of the <i>text</i> bytes.</p>
</div></div><aname="utils-keccak256"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">keccak256</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-keccak256"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/keccak256/src.ts/index.ts#L7">source</a></div></div><divclass="body"><p>Returns the <ahref="https://en.wikipedia.org/wiki/SHA-3">KECCAK256</a> digest <i>aBytesLike</i>.</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/ethers-v5-beta/packages/sha2/src.ts/index.ts#L14">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/ethers-v5-beta/packages/sha2/src.ts/index.ts#L18">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/ethers-v5-beta/packages/sha2/src.ts/index.ts#L22">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/ethers-v5-beta/packages/sha2/src.ts/index.ts#L27">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/ethers-v5-beta/packages/hash/src.ts/index.ts#L53">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>
</div></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/ethers-v5-beta/packages/hash/src.ts/index.ts#L29">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>
</div></div><divclass="code-title"><div>Hashing Messages</div></div><divclass="code"><spanclass="comment">// @TODO: include examples of hashMessage; it can be complex. :)
</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/ethers-v5-beta/packages/solidity/src.ts/index.ts#L73">source</a></div></div><divclass="body"><p>Returns the non-standard encoded <i>values</i> packed according to their respecive 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/ethers-v5-beta/packages/solidity/src.ts/index.ts#L82">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/ethers-v5-beta/packages/solidity/src.ts/index.ts#L86">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>. Last modified on June 12, 2020, 7:17pm.</div>