|
| 1 | +_section: Error Codes @<error-codes> |
| 2 | + |
| 3 | +All errors in ethers are created by the [[Logger]] class, which includes |
| 4 | +a number of additional properties and extra data, which can assist in |
| 5 | +debugging and when submitting issues. |
| 6 | + |
| 7 | +When submitting an issue, please include as much of any error as possible, |
| 8 | +but also make sure you understand the error and have tried suggested solutions |
| 9 | +both in this trouble-shooting document and any other issues you find when |
| 10 | +searching the GitHub issues. |
| 11 | + |
| 12 | + |
| 13 | +_subsection: CALL_EXCEPTION @<help-CALL_EXCEPTION> |
| 14 | + |
| 15 | +This error occurs when a call or transaction is used to interact with |
| 16 | +the blockchain reverts (via ``revert``, ``require``, et cetera). |
| 17 | + |
| 18 | +Due to the overall flexibility of Ethereum and Turing Completeness, |
| 19 | +there is a large variety of reasons this can occur and troubleshooting |
| 20 | +requires attention. |
| 21 | + |
| 22 | + |
| 23 | +_heading: Common Causes |
| 24 | + |
| 25 | +- The code does not exist on-chain. This may happen if you failed to wait |
| 26 | + until the contract was deployed, the address is incorrect or if you |
| 27 | + are connected to a different network than the contract has been deployed. |
| 28 | + Check the code exists using ``provider.getCode(address)``. |
| 29 | +- The wrong code is being accessed, for example if an artifact file was |
| 30 | + not correctly updated so an older instance of the contract is being called |
| 31 | +- The contract is failing during a ``require`` statement. For example, if |
| 32 | + a contract method requires an //admin account// to be used, but the |
| 33 | + contract is connected to another [[Signer]]. |
| 34 | +- The wrong ABI is being used to interact with a contract. |
| 35 | + |
| 36 | +_heading: Debugging |
| 37 | + |
| 38 | +- Always double check the address and network you are connected to and use |
| 39 | + ``provider.getCode(address)`` to verify the deployed code matches your |
| 40 | + most recent version. |
| 41 | +- Try accessing other, simpler contract methods to verify the account is correct. |
| 42 | + |
| 43 | + |
| 44 | +_subsection: INSUFFICIENT_FUNDS @<help-INSUFFICIENT_FUNDS> |
| 45 | + |
| 46 | +This usually occurs when a transaction is attempted, but the sending account |
| 47 | +does not have enough ether to cover the cost of the transaction. |
| 48 | + |
| 49 | +A transaction has an intrinsic cost which must be met, which accounts for |
| 50 | +the value being sent, the base fee of the transaction, additional fees per byte |
| 51 | +of calldata and whether the transaction will create a new account (i.e. the ``to`` |
| 52 | +is empty). |
| 53 | + |
| 54 | +This error can also happen if ``provider.estimateGas`` is used with a non-zero |
| 55 | +fee (i.e. ``gasPrice``, ``maxFeePerGas`` or ``maxPriorityFeePerGas``). If any |
| 56 | +fee properties are specified, the ``from`` account must have sufficient ether |
| 57 | +to execute the transaction. |
| 58 | + |
| 59 | + |
| 60 | +_subsection: MISSING_NEW @<help-MISSING_NEW> |
| 61 | + |
| 62 | +Classes in ethers must be instantiated with the ``new`` operator. This |
| 63 | +error indicates that a Class is attempting to be used as a function. |
| 64 | + |
| 65 | +_code: Examples @lang<javascript> |
| 66 | + |
| 67 | +//_hide: privateKey = "0x0123456789012345678901234567890123456789012345678901234567890123"; |
| 68 | +//_hide: Wallet = ethers.Wallet; |
| 69 | + |
| 70 | +// Bad: |
| 71 | +//_throws: |
| 72 | +ethers.Wallet(privateKey) |
| 73 | +//_log: |
| 74 | + |
| 75 | +// Good: |
| 76 | +//_result: |
| 77 | +new ethers.Wallet(privateKey) |
| 78 | +//_log: |
| 79 | + |
| 80 | + |
| 81 | +_subsection: NONCE_EXPIRED @<help-NONCE_EXPIRED> |
| 82 | + |
| 83 | +This error occurs when a transaction is being sent with a ``nonce`` that |
| 84 | +is lower than next required ``nonce``. |
| 85 | + |
| 86 | +Each Ethereum transaction requires a ``nonce`` property equal to the index |
| 87 | +of that transaction for that account for all time. So, if an account has |
| 88 | +send four transactions over its lifetime, that means the nonces 0 though 3 |
| 89 | +(inclusive) have been used. The next transaction must use a nonce of 4. |
| 90 | +Attempting to re-use a nonce less than 4 will result in this error. |
| 91 | + |
| 92 | + |
| 93 | +_subsection: NUMERIC_FAULT @<help-NUMERIC_FAULT> |
| 94 | + |
| 95 | +A [numeric fault](errors--numeric-fault) is a consequence of |
| 96 | +performing an illegal operation with numeric values, such as |
| 97 | +dividing by zero. |
| 98 | + |
| 99 | +The error will indicate the ``operation``, which further indicates |
| 100 | +the reason for the error. |
| 101 | + |
| 102 | + |
| 103 | +_heading: Overflow @<help-NUMERIC_FAULT-overflow> |
| 104 | + |
| 105 | +JavaScript uses [IEEE 754 double-precision binary floating point](link-wiki-ieee754) |
| 106 | +numbers to represent numeric values. As a result, there are //holes// |
| 107 | +in the integer set after 9,007,199,254,740,991; which is |
| 108 | +problematic for //Ethereum// because that is only around 0.009 |
| 109 | +ether (in wei), which means any value over that will begin to |
| 110 | +experience rounding errors. |
| 111 | + |
| 112 | +As a result, any attempt to use a number which is outside the safe |
| 113 | +range, which would result in incorrect values, an error is thrown. |
| 114 | + |
| 115 | +In general, numbers should be kept as strings, [[BigNumber]] instances or |
| 116 | +using ES2020 bigints, which all can safely be used without loss of precission. |
| 117 | + |
| 118 | +_code: Examples @lang<javascript> |
| 119 | + |
| 120 | +// One ether is outside the safe range |
| 121 | +//_throws: |
| 122 | +BigNumber.from(1000000000000000000) |
| 123 | +//_log: |
| 124 | + |
| 125 | +// Providing the value as a string is safe |
| 126 | +//_result: |
| 127 | +BigNumber.from("1000000000000000000") |
| 128 | +//_log: |
| 129 | + |
| 130 | +// As is using a bigint (notice the `n` suffix) |
| 131 | +//_result: |
| 132 | +BigNumber.from(1000000000000000000n) |
| 133 | +//_log: |
| 134 | + |
| 135 | +// But most often, the `parseEther` function solves this |
| 136 | +//_result: |
| 137 | +utils.parseEther("1.0") |
| 138 | +//_log: |
| 139 | + |
| 140 | + |
| 141 | +_heading: Numeric Underflow @<help-NUMERIC_FAULT-underflow> |
| 142 | + |
| 143 | +Numeric underflow sbould not be confused with overflow. |
| 144 | + |
| 145 | +Numeric underflow occurs when the precission of a value cannot be |
| 146 | +safely represented in the current data type. |
| 147 | + |
| 148 | +**Common Causes** |
| 149 | + |
| 150 | +- Using values with fractional componets (e.g. ``BigNumber.from(1.2)``). |
| 151 | + If you require fractions, you must use the [[FixedNumber]] class. |
| 152 | +- Parsing string values that have more decimals than the unit supports |
| 153 | + (e.g. ``parseUints("1.33", 1)``). |
| 154 | + |
| 155 | +_code: Examples @lang<javascript> |
| 156 | + |
| 157 | +// BigNumbers cannot be created with a fractional component |
| 158 | +//_throws: |
| 159 | +BigNumber.from(1.2) |
| 160 | +//_log: |
| 161 | + |
| 162 | +// Parsing a value with more decimals than the type |
| 163 | +//_throws: |
| 164 | +utils.parseUnits("1.34", 1); |
| 165 | +//_log: |
| 166 | + |
| 167 | + |
| 168 | +_heading: Division by zero @<help-NUMERIC_FAULT-division-by-zero> |
| 169 | + |
| 170 | +This error occurs when dividing by zero or attempting to take the modulo zero. |
| 171 | + |
| 172 | + |
| 173 | +_heading: Unbound Result @<help-NUMERIC_FAULT-unbound-result> |
| 174 | + |
| 175 | +The ethers [[BigNumber]] does not support bitwise operators |
| 176 | +on negative numbers which can result in the need for an infinite |
| 177 | +number of set bits. |
| 178 | + |
| 179 | +Other implementations may use negative values to indicate this, |
| 180 | +but this is considered out of scope for ethers. |
| 181 | + |
| 182 | + |
| 183 | +_heading: Unsupported Operation @<help-NUMERIC_FAULT-unsupported> |
| 184 | + |
| 185 | +The ethers [[BigNumber]] does not support negative powers or bitwise |
| 186 | +shift operation using negative values. |
| 187 | + |
| 188 | +_code: Examples @lang<javascript> |
| 189 | + |
| 190 | +two = BigNumber.from(2); |
| 191 | + |
| 192 | +//_throws: |
| 193 | +two.pow(-2) |
| 194 | +//_log: |
| 195 | + |
| 196 | +// Cannot use negative values to alter shift direction |
| 197 | +//_throws: |
| 198 | +two.shr(-1) |
| 199 | +//_log: |
| 200 | + |
| 201 | + |
| 202 | +_subsection: REPLACEMENT_UNDERPRICED @<help-REPLACEMENT_UNDERPRICED> |
| 203 | + |
| 204 | +To prevent nodes from being overloaded with junk transactions, a transaction |
| 205 | +is only accepted into the memory pool if it has a reasonable chance of being |
| 206 | +actually mined, which means that the account has sufficient balance, the nonce |
| 207 | +is correct and the fee seems reasonable. |
| 208 | + |
| 209 | +Once a transaction is in the memory pool though, to prevent an account from |
| 210 | +flooding the network with many different transactions with the same nonce (each |
| 211 | +of which satisfies the above criteria), to replace an existing transaction |
| 212 | +an additional committment of a fee must be made by increasing the promised fee. |
| 213 | + |
| 214 | +When replacing a legacy non-EIP1559 transaction, the ``gasPrice`` must be |
| 215 | +increased. When replacing a modern, EIP-1559 transaction, the ``maxPriorityFeePerGas`` |
| 216 | +should be increased. |
| 217 | + |
| 218 | + |
| 219 | +_subsection: TRANSACTION_REPLACED @<help-TRANSACTION_REPLACED> |
| 220 | + |
| 221 | +This error is thrown when waiting for a transaction which has been |
| 222 | +replaced by another, by the sender submitting a second transaction |
| 223 | +with the same nonce, while the transaction was pending in the |
| 224 | +transaction pool. |
| 225 | + |
| 226 | +You can learn more about this feature in the ``.wait`` method of |
| 227 | +[TransactionResponse](providers-TransactionResponse). |
| 228 | + |
| 229 | + |
| 230 | +_subsection: UNPREDICTABLE_GAS_LIMIT @<help-UNPREDICTABLE_GAS_LIMIT> |
| 231 | + |
| 232 | +During gas estimation it is possible that a transaction would actually |
| 233 | +fail (and hence has no reasonable estimate of gas requirements) or that |
| 234 | +the transaction is complex in a way that does not permit a node to |
| 235 | +estiamte the gas requirements, in which case this error is thrown. |
| 236 | + |
| 237 | +In almost all cases, this will unfortunately require you specify an |
| 238 | +explicit ``gasLimit`` for your transaction, which will disable ether's |
| 239 | +automatic population of the ``gasLimit`` field, which will cause this |
| 240 | +error to go away. |
| 241 | + |
| 242 | +To dial in an appropriate gas limit, try a value that is much higher |
| 243 | +than you expect, and then make a few transactions to discover reasonable |
| 244 | +values and then you can reduce this value down to that ballpark. |
| 245 | + |
| 246 | +Keep in mind this error can also occur if the transaction would |
| 247 | +legitimately fail, in which case the root cause must be addressed, such |
| 248 | +as ensuring the correct [[Signer]] is being used, the appropriate allowance |
| 249 | +for an ERC-20 token has been approved, etc. |
0 commit comments