<html><head><title>Byte Manipulation</title><linkrel="stylesheet"type="text/css"href="/static/style.css"></head><body><divclass="sidebar"><divclass="header"><divclass="logo"><ahref="/"><divclass="image"></div><divclass="name">ethers</div><divclass="version">v5.0-beta</div></a></div></div><divclass="toc"><div><divclass="link title"><ahref="/">Documentation</a></div><divclass="base show link depth-1"><ahref="/getting-started/">Getting Started</a></div><divclass="hide link depth-2"><ahref="/getting-started/#installing">Installing</a></div><divclass="hide link depth-2"><ahref="/getting-started/#importing">Importing</a></div><divclass="base show link depth-1"><ahref="/concepts/">Concepts</a></div><divclass="hide link depth-2"><ahref="/concepts/events/">Events</a></div><divclass="hide link depth-3"><ahref="/concepts/events/#solidity-topics">Solidity Topics</a></div><divclass="hide link depth-2"><ahref="/concepts/gas/">Gas</a></div><divclass="hide link depth-3"><ahref="/concepts/gas/#gas-price">Gas Price</a></div><divclass="hide link depth-3"><ahref="/concepts/gas/#gas-limit">Gas Limit</a></div><divclass="base ancestor show link depth-1"><ahref="/api/">Application Programming Interface</a></div><divclass="show link depth-2"><ahref="/api/contract/">Contracts</a></div><divclass="hide link depth-3"><ahref="/api/contract/#buckets">Buckets</a></div><divclass="show link depth-2"><ahref="/api/signer/">Signers</a></div><divclass="hide link depth-3"><ahref="/api/signer/#signer">Signer</a></div><divclass="hide link depth-3"><ahref="/api/signer/#wallet">Wallet</a></div><divclass="hide link depth-3"><ahref="/api/signer/#voidsigner">VoidSigner</a></div><divclass="hide link depth-3"><ahref="/api/signer/#externallyownedaccount">ExternallyOwnedAccount</a></div><divclass="show link depth-2"><ahref="/api/providers/">Providers</a></div><divclass="hide link depth-3"><ahref="/api/providers/provider/">Provider</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#accounts-methods">Accounts Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#blocks-methods">Blocks Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#ethereum-naming-service-(ens)-methods">Ethereum Naming Service (ENS) Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#logs-methods">Logs Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#network-status-methods">Network Status Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#transactions-methods">Transactions Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#event-emitter-methods">Event Emitter Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#inspection-methods">Inspection Methods</a></div><divclass="hide link depth-3"><ahref="/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/jsonrpc-provider/#jsonrpcsigner">JsonRpcSigner</a></div><divclass="hide link depth-4"><ahref="/api/providers/jsonrpc-provider/#jsonrpcuncheckedsigner">JsonRpcUncheckedSigner</a></div><divclass="hide link depth-3"><ahref="/api/providers/api-providers/">API Providers</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#etherscanprovider">EtherscanProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#infuraprovider">InfuraProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#alchemyprovider">AlchemyProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#cloudfrontprovider">CloudfrontProvider</a></div><divclass="hide link depth-3"><ahref="/api/providers/other/">Other Providers</a></div><divclass="hide link depth-4"><ahref="/api/providers/other/#fallbackprovider">FallbackProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/other/#ipcprovider">IpcProvider</a></div><div
<p>A <b>Bytes</b> is any object which is an <ahref="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a> or <ahref="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray">TypedArray</a> with each value in the valid byte range (i.e. between 0 and 255 inclusive), or is an Object with a <codeclass="inline">length</code> property where each indexed property is in the valid byte range.</p>
<p>A <b>DataHexstring</b> is identical to a <ahref="/api/utils/bytes/#hexstring">Hexstring</a> except that it has an even number of nibbles, and therefore is a valid representation of binary data as a string.</p>
<p>A <b>Hexstring</b> is a string which has a <codeclass="inline">0x</code> prefix followed by any number of nibbles (i.e. case-insensitive hexidecumal characters, <codeclass="inline">0-9</code> and <codeclass="inline">a-f</code>).</p>
<ul><li><b>r</b> and <b>s</b>— The x co-ordinate of <b>r</b> and the <b>s</b> value of the signature</li><li><b>v</b>— The parity of the y co-ordinate of <b>r</b></li><li><b>_vs</b>— The <ahref="https://eips.ethereum.org/EIPS/eip-2098">compact representation</a> of the <b>s</b> and <b>v</b></li><li><b>recoveryParam</b>— The normalized (i.e. 0 or 1) value of <b>v</b></li></ul>
<p>A <b>Flat-Format Signature</b> is a common Signature format where the r, s and v are concanenated into a 65 byte (130 nibble) <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a>.</p>
<p>A <b>SignatureLike</b> is similar to a <ahref="/api/utils/bytes/#signature">Signature</a>, except redundant properties may be omitted or it may be a <ahref="/api/utils/bytes/#signature-flat">Flat-Format Signature</a>.</p><p>For example, if <b>_vs</b> is specified, <b>s</b> and <b>v</b> may be omitted. Likewise, if <b>recoveryParam</b> is provided, <b>v</b> may be omitted (as in these cases the missing values can be computed).</p>
<aname="utils-isbytes"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">isBytes</span> ( <spanclass="param">object</span> ) <spanclass="arrow">⇒</span><spanclass="returns">boolean</span><divclass="anchors"><aclass="self"href="#utils-isbytes"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L73">source</a></div></div><divclass="body"><p>Returns true if and only if <i>object</i> is a valid <ahref="/api/utils/bytes/#bytes">Bytes</a>.</p></div></div>
<aname="utils-isbyteslike"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">isBytesLike</span> ( <spanclass="param">object</span> ) <spanclass="arrow">⇒</span><spanclass="returns">boolean</span><divclass="anchors"><aclass="self"href="#utils-isbyteslike"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L69">source</a></div></div><divclass="body"><p>Returns true if and only if <i>object</i> is a <ahref="/api/utils/bytes/#bytes">Bytes</a> or <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a>.</p></div></div>
<aname="utils-ishexstring"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">isHexString</span> ( <spanclass="param">object</span> , [ <spanclass="param">length</span> ] ) <spanclass="arrow">⇒</span><spanclass="returns">boolean</span><divclass="anchors"><aclass="self"href="#utils-ishexstring"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L184">source</a></div></div><divclass="body"><p>Returns true if and only if <i>object</i> is a valid hex string. If <i>length</i> is specified and <i>object</i> is not a valid <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a> of <i>length</i> bytes, an InvalidArgument error is thrown.</p></div></div>
<aname="converting-between-arrays-and-hexstrings"></a><h2class="show-anchors"><div>Converting between Arrays and Hexstrings<divclass="anchors"><aclass="self"href="#converting-between-arrays-and-hexstrings"></a></div></div></h2>
<aname="utils-arrayify"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">arrayify</span> ( <spanclass="param">datahexstringOrArrayish</span> [ , <spanclass="param">options</span> ] ) <spanclass="arrow">⇒</span><spanclass="returns">Uint8Array</span><divclass="anchors"><aclass="self"href="#utils-arrayify"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L91">source</a></div></div><divclass="body"><p>Converts <i>datahexstringOrArrayish</i> to a Uint8Array.</p></div></div>
<aname="utils-hexlify"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexlify</span> ( <spanclass="param">hexstringOrArrayish</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string< <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a> ></span><divclass="anchors"><aclass="self"href="#utils-hexlify"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L194">source</a></div></div><divclass="body"><p>Converts <i>hexstringOrArrayish</i> to a <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a>.</p></div></div>
<aname="utils-hexvalue"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexValue</span> ( <spanclass="param">aBigNumberish</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string< <ahref="/api/utils/bytes/#hexstring">Hexstring</a> ></span><divclass="anchors"><aclass="self"href="#utils-hexvalue"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L287">source</a></div></div><divclass="body"><p>Converts <i>aBigNumberish</i> to a <ahref="/api/utils/bytes/#hexstring">Hexstring</a>, with no <u>unnecessary</u> leading zeros.</p></div></div>
<aname="utils-concat"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">concat</span> ( <spanclass="param">arrayOfBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">Uint8Array</span><divclass="anchors"><aclass="self"href="#utils-concat"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L140">source</a></div></div><divclass="body"><p>Concatenates all the <ahref="/api/utils/bytes/#byteslike">BytesLike</a> in <i>arrayOfBytesLike</i> into a single Uint8Array.</p></div></div>
<aname="utils-stripzeros"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">stripZeros</span> ( <spanclass="param">aBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">Uint8Array</span><divclass="anchors"><aclass="self"href="#utils-stripzeros"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L154">source</a></div></div><divclass="body"><p>Returns a Uint8Array with all leading <codeclass="inline">0</code> bytes of <i>aBtyesLike</i> removed.</p></div></div>
<aname="utils-zeropad"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">zeroPad</span> ( <spanclass="param">aBytesLike</span> , <spanclass="param">length</span> ) <spanclass="arrow">⇒</span><spanclass="returns">Uint8Array</span><divclass="anchors"><aclass="self"href="#utils-zeropad"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L171">source</a></div></div><divclass="body"><p>Retutns a Uint8Array of the data in <i>aBytesLike</i> with <codeclass="inline">0</code> bytes prepended to <i>length</i> bytes long.</p><p>If <i>aBytesLike</i> is already longer than <i>length</i> bytes long, an InvalidArgument error will be thrown.</p></div></div>
<aname="utils-hexconcat"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexConcat</span> ( <spanclass="param">arrayOfBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string< <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a> ></span><divclass="anchors"><aclass="self"href="#utils-hexconcat"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L279">source</a></div></div><divclass="body"><p>Concatenates all the <ahref="/api/utils/bytes/#byteslike">BytesLike</a> in <i>arrayOfBytesLike</i> into a single <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a></p></div></div>
<aname="utils-hexdatalength"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexDataLength</span> ( <spanclass="param">aBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string< <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a> ></span><divclass="anchors"><aclass="self"href="#utils-hexdatalength"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L253">source</a></div></div><divclass="body"><p>Returns the length (in bytes) of <i>aBytesLike</i>.</p></div></div>
<aname="utils-hexdataslice"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexDataSlice</span> ( <spanclass="param">aBytesLike</span> , <spanclass="param">offset</span> [ , <spanclass="param">endOffset</span> ] ) <spanclass="arrow">⇒</span><spanclass="returns">string< <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a> ></span><divclass="anchors"><aclass="self"href="#utils-hexdataslice"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L263">source</a></div></div><divclass="body"><p>Returns a <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a> representation of a slice of <i>aBytesLike</i>, from <i>offset</i> (in bytes) to <i>endOffset</i> (in bytes). If <i>endOffset</i> is omitted, the length of <i>aBytesLike</i> is used.</p></div></div>
<aname="utils-hexstripzeros"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexStripZeros</span> ( <spanclass="param">aBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string< <ahref="/api/utils/bytes/#hexstring">Hexstring</a> ></span><divclass="anchors"><aclass="self"href="#utils-hexstripzeros"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L293">source</a></div></div><divclass="body"><p>Returns a <ahref="/api/utils/bytes/#hexstring">Hexstring</a> representation of <i>aBytesLike</i> with all leading zeros removed.</p></div></div>
<aname="utils-hexzeropad"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexZeroPad</span> ( <spanclass="param">aBytesLike</span> , <spanclass="param">length</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string< <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a> ></span><divclass="anchors"><aclass="self"href="#utils-hexzeropad"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L305">source</a></div></div><divclass="body"><p>Returns a <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a> representation of <i>aBytesLike</i> padded to <i>length</i> bytes.</p><p>If <i>aBytesLike</i> is already longer than <i>length</i> bytes long, an InvalidArgument error will be thrown.</p></div></div>
<aname="utils-joinsignature"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">joinSignature</span> ( <spanclass="param">aSignatureLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string< <ahref="/api/utils/bytes/#signature-flat">FlatSignature</a> ></span><divclass="anchors"><aclass="self"href="#utils-joinsignature"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L442">source</a></div></div><divclass="body"><p>Return the flat-format of <i>aSignaturelike</i>, which is 65 bytes (130 nibbles) long, concatenating the <b>r</b>, <b>s</b> and (normalized) <b>v</b> of a Signature.</p></div></div>
<aname="utils-splitsignature"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">splitSignature</span> ( <spanclass="param">aSignatureLikeOrBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns"><ahref="/api/utils/bytes/#signature">Signature</a></span><divclass="anchors"><aclass="self"href="#utils-splitsignature"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/bytes/src.ts/index.ts#L323">source</a></div></div><divclass="body"><p>Return the full expanded-format of <i>aSignaturelike</i> or a flat-format <ahref="/api/utils/bytes/#datahexstring">DataHexstring</a>. Any missing properties will be computed.</p></div></div>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span> . <spanclass="path">utils</span> . <spanclass="method">randomBytes</span> ( <spanclass="param">length</span> ) <spanclass="arrow">⇒</span><spanclass="returns">Uint8Array</span><divclass="anchors"></div></div><divclass="body"><p>Return a new Uint8Array of <i>length</i> random bytes.</p></div></div><divclass="footer"><divclass="nav previous"><ahref="/api/utils/bignumber/"><spanclass="arrow">←</span>BigNumber</a></div><divclass="nav next"><ahref="/api/utils/constants/">Constants<spanclass="arrow">→</span></a></div></div><divclass="copyright">The content of this site is licensed under the <ahref="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons Attribution 4.0 International License</a>.</div></div><scriptsrc="/script.js"type="text/javascript"></script></body></html><!-- ContentHash:41882a2bd89dad9b58819ecf614d21d4e52eb11c50f1fba0ebbe3446a71ca069 -->