<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 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="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="myself ancestor ancestor 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="hideli
<aname="logging"></a><aname="logging"></a><h1class="show-anchors"><div>Logging<divclass="anchors"><aclass="self"href="/v5/api/utils/logger/#logging"></a></div></div></h1><p>These are just a few simple logging utilities provided to simplify and standardize the error facilities across the Ethers library.</p>
<p>The <ahref="/v5/api/utils/logger/#Logger">Logger</a> library has zero dependencies and is intentionally very light so it can be easily included in each library.</p>
<p>The <ahref="/v5/api/utils/logger/#Logger--censorship">Censorship</a> functionality relies on one instance of the Ethers library being included. In large bundled packages or when <codeclass="inline">npm link</code> is used, this may not be the case. If you require this functionality, ensure that your bundling is configured properly.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="modifier">new </span><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">Logger</span><spanclass="symbol">(</span><spanclass="param">version</span><spanclass="symbol">)</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L150">source</a></div></div><divclass="body"><p>Create a new logger which will include <i>version</i> in all errors thrown.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="method">globalLogger</span><spanclass="symbol">(</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/logger/#Logger">Logger</a></span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L308">source</a></div></div><divclass="body"><p>Returns the singleton global logger.</p>
</div></div><aname="logging--Logger--errors"></a><h3class="show-anchors"><div>Errors<divclass="anchors"><aclass="self"href="/v5/api/utils/logger/#logging--Logger--errors"></a></div></div></h3><p>These functions honor the current <ahref="/v5/api/utils/logger/#Logger--censorship">Censorship</a> and help create a standard error model for detecting and processing errors within Ethers.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">logger</span><spanclass="symbol">.</span><spanclass="method">makeError</span><spanclass="symbol">(</span><spanclass="param">message</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">code</span> = <spanclass="param">UNKNOWN_ERROR</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">params</span><spanclass="symbol">]</span><spanclass="symbol">]</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">Error</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L179">source</a></div></div><divclass="body"><p>Create an Error object with <i>message</i> and an optional <i>code</i> and additional <i>params</i> set. This is useful when an error is needed to be rejected instead of thrown.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">logger</span><spanclass="symbol">.</span><spanclass="method">throwError</span><spanclass="symbol">(</span><spanclass="param">message</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">code</span> = <spanclass="param">UNKNOWN_ERROR</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">params</span><spanclass="symbol">]</span><spanclass="symbol">]</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">never</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L216">source</a></div></div><divclass="body"><p>Throw an Error with <i>message</i> and an optional <i>code</i> and additional <i>params</i> set.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">logger</span><spanclass="symbol">.</span><spanclass="method">throwArgumentError</span><spanclass="symbol">(</span><spanclass="param">message</span><spanclass="symbol">,</span><spanclass="param">name</span><spanclass="symbol">,</span><spanclass="param">value</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">never</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L220">source</a></div></div><divclass="body"><p>Throw an <ahref="/v5/api/utils/logger/#errors-InvalidArgument">INVALID_ARGUMENT</a> Error with <i>name</i> and <i>value</i>.</p>
</div></div><aname="logging--Logger--usage-validation"></a><h3class="show-anchors"><div>Usage Validation<divclass="anchors"><aclass="self"href="/v5/api/utils/logger/#logging--Logger--usage-validation"></a></div></div></h3><p>There can be used to ensure various properties and actions are safe.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">logger</span><spanclass="symbol">.</span><spanclass="method">checkAbstract</span><spanclass="symbol">(</span><spanclass="param">target</span><spanclass="symbol">,</span><spanclass="param">kind</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">void</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L296">source</a></div></div><divclass="body"><p>Checks that <i>target</i> is not <i>kind</i> and performs the same operatons as <codeclass="inline">checkNew</code>. This is useful for ensuring abstract classes are not being instantiated.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">logger</span><spanclass="symbol">.</span><spanclass="method">checkArgumentCount</span><spanclass="symbol">(</span><spanclass="param">count</span><spanclass="symbol">,</span><spanclass="param">expectedCound</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">message</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">void</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L268">source</a></div></div><divclass="body"><p>If <i>count</i> is not equal to <i>expectedCount</i>, throws a <ahref="/v5/api/utils/logger/#errors-MissingArgument">MISSING_ARGUMENT</a> or <ahref="/v5/api/utils/logger/#errors-UnexpectedArgument">UNEXPECTED_ARGUMENT</a> error.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">logger</span><spanclass="symbol">.</span><spanclass="method">checkNew</span><spanclass="symbol">(</span><spanclass="param">target</span><spanclass="symbol">,</span><spanclass="param">kind</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">void</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L290">source</a></div></div><divclass="body"><p>If <i>target</i> is not a valid <codeclass="inline">this</code> or <codeclass="inline">target</code> value, throw a <ahref="/v5/api/utils/logger/#errors-MissingNew">MISSING_NEW</a> error. This is useful to ensure callers of a Class are using <codeclass="inline">new</code>.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">logger</span><spanclass="symbol">.</span><spanclass="method">checkNormalize</span><spanclass="symbol">(</span><spanclass="param">message</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">void</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L237">source</a></div></div><divclass="body"><p>Check that the environment has a correctly functioning <ahref="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize">String.normalize</a>. If not, a <ahref="/v5/api/utils/logger/#errors-UnsupportedOperation">UNSUPPORTED_OPERATION</a> error is thrown.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">logger</span><spanclass="symbol">.</span><spanclass="method">checkSafeUint53</span><spanclass="symbol">(</span><spanclass="param">value</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">message</span><spanclass="symbol">]</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">void</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L246">source</a></div></div><divclass="body"><p>If <i>value</i> is not safe as a <ahref="https://en.wikipedia.org/wiki/Double-precision_floating-point_format">JavaScript number</a>, throws a <ahref="/v5/api/utils/logger/#errors-NumericFault">NUMERIC_FAULT</a> error.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="method">setLogLevel</span><spanclass="symbol">(</span><spanclass="param">logLevel</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">void</span><divclass="anchors"><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/logger/src.ts/index.ts#L331">source</a></div></div><divclass="body"><p>Set the log level, to suppress logging output below a <ahref="/v5/api/utils/logger/#Logger-levels">particular log level</a>.</p>
</div></div><aname="errors"></a><aname="logging--errors"></a><h2class="show-anchors"><div>Errors<divclass="anchors"><aclass="self"href="/v5/api/utils/logger/#errors"></a></div></div></h2><p>Every error in Ethers has a <codeclass="inline">code</code> value, which is a string that will match one of the following error codes.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">NOT_IMPLEMENTED</span><divclass="anchors"></div></div><divclass="body"><p>The operation is not implemented.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">SERVER_ERROR</span><divclass="anchors"></div></div><divclass="body"><p>There was an error communicating with a server.</p>
</div></div><aname="errors-UnsupportedOperation"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">UNSUPPORTED_OPERATION</span><divclass="anchors"><aclass="self"href="/v5/api/utils/logger/#errors-UnsupportedOperation"></a></div></div><divclass="body"><p>The operation is not supported.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">BUFFER_OVERRUN</span><divclass="anchors"></div></div><divclass="body"><p>The amount of data needed is more than the amount of data required, which would cause the data buffer to read past its end.</p>
</div></div><aname="errors-NumericFault"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">NUMERIC_FAULT</span><divclass="anchors"><aclass="self"href="/v5/api/utils/logger/#errors-NumericFault"></a></div></div><divclass="body"><p>There was an invalid operation done on numeric values.</p>
<p>Common cases of this occur when there is <ahref="https://en.wikipedia.org/wiki/Integer_overflow">overflow</a>, <ahref="https://en.wikipedia.org/wiki/Arithmetic_underflow">arithmetic underflow</a> in fixed numeric types or division by zero.</p>
<aname="errors-InvalidArgument"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">INVALID_ARGUMENT</span><divclass="anchors"><aclass="self"href="/v5/api/utils/logger/#errors-InvalidArgument"></a></div></div><divclass="body"><p>The type or value of an argument is invalid. This will generally also include the <codeclass="inline">name</code> and <codeclass="inline">value</code> of the argument. Any function which accepts sensitive data (such as a private key) will include the string <codeclass="inline">[[REDACTED]]</code> instead of the value passed in.</p>
</div></div><aname="errors-MissingArgument"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">MISSING_ARGUMENT</span><divclass="anchors"><aclass="self"href="/v5/api/utils/logger/#errors-MissingArgument"></a></div></div><divclass="body"><p>An expected parameter was not specified.</p>
</div></div><aname="errors-MissingNew"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">MISSING_NEW</span><divclass="anchors"><aclass="self"href="/v5/api/utils/logger/#errors-MissingNew"></a></div></div><divclass="body"><p>An object is a Class, but is now being called with <codeclass="inline">new</code>.</p>
</div></div><aname="errors-UnexpectedArgument"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">UNEXPECTED_ARGUMENT</span><divclass="anchors"><aclass="self"href="/v5/api/utils/logger/#errors-UnexpectedArgument"></a></div></div><divclass="body"><p>Too many parameters we passed into a function.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">CALL_EXCEPTION</span><divclass="anchors"></div></div><divclass="body"><p>An attempt to call a blockchain contract (getter) resulted in a revert or other error.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">INSUFFICIENT_FUNDS</span><divclass="anchors"></div></div><divclass="body"><p>The account is attempting to make a transaction which costs more than is available.</p>
<p>A sending account must have enough ether to pay for the value, the gas limit (at the gas price) as well as the intrinsic cost of data. The intrinsic cost of data is 4 gas for each zero byte and 68 gas for each non-zero byte.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">NETWORK_ERROR</span><divclass="anchors"></div></div><divclass="body"><p>An Ethereum network validation error, such as an invalid chain ID.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">NONCE_EXPIRED</span><divclass="anchors"></div></div><divclass="body"><p>The nonce being specified has already been used in a mined transaction.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">REPLACEMENT_UNDERPRICED</span><divclass="anchors"></div></div><divclass="body"><p>When replacing a transaction, by using a nonce which has already been sent to the network, but which has not been mined yet the new transaction must specify a higher gas price.</p>
<p>This error occurs when the gas price is insufficient to <i>bribe</i> the transaction pool to prefer the new transaction over the old one. Generally, the new gas price should be about 50% + 1 wei more, so if a gas price of 10 gwei was used, the replacement should be 15.000000001 gwei.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">errors</span><spanclass="symbol">.</span><spanclass="method">UNPREDICTABLE_GAS_LIMIT</span><divclass="anchors"></div></div><divclass="body"><p>When estimating the required amount of gas for a transaction, a node is queried for its best guess.</p>
<p>If a node is unable (or unwilling) to predict the cost, this error occurs.</p>
<p>The best remedy for this situation is to specify a gas limit in the transaction manually.</p>
<p>This error can also indicate that the transaction is expected to fail regardless, if for example an account with no tokens is attempting to send a token.</p>
<divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">levels</span><spanclass="symbol">.</span><spanclass="method">DEBUG</span><divclass="anchors"></div></div><divclass="body"><p>Log all output, including debugging information.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">levels</span><spanclass="symbol">.</span><spanclass="method">INFO</span><divclass="anchors"></div></div><divclass="body"><p>Only log output for infomational, warnings and errors.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">levels</span><spanclass="symbol">.</span><spanclass="method">WARNING</span><divclass="anchors"></div></div><divclass="body"><p>Only log output for warnings and errors.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">levels</span><spanclass="symbol">.</span><spanclass="method">ERROR</span><divclass="anchors"></div></div><divclass="body"><p>Only log output for errors.</p>
</div></div><divclass="property show-anchors"><divclass="signature"><spanclass="path">Logger</span><spanclass="symbol">.</span><spanclass="path">levels</span><spanclass="symbol">.</span><spanclass="method">OFF</span><divclass="anchors"></div></div><divclass="body"><p>Do not output any logs.</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 September 8, 2020, 1:8am.</div>