Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

TypeError: Cannot use 'in' operator to search for 'originalError' in null #6433

@volodmrr

Description

@volodmrr

Expected behavior

Throwing error with message that my transaction/gas estimating was reverted

Actual behavior

\web3-errors\src\errors\contract_errors.ts:163 line throws next error:

 if ('originalError' in error.data) {
TypeError: Cannot use 'in' operator to search for 'originalError' in null

It can be thrown by web3.eth..estimateGas() or w3.eth.sendSignedTransaction().

My transaction was reverted and I just logged it in console (in library code) to understand what happened. Error object is:

{
  "code": -32000,
  "message": "execution reverted",
  "data": null
}

As soon as typeof null === 'object' is true web3-errors library throws an error above in this code:

if (typeof error.data === 'object') {
            let originalError;
            if ('originalError' in error.data) {

Error throwed in web3-errors\src\errors\contract_errors.ts:163

Steps to reproduce the behavior

I don't actually know why transaction is reverted. Code throws it randomly.

Logs

root\node_modules\web3-errors\src\errors\contract_errors.ts:163
                        if ('originalError' in error.data) {
                    ^
TypeError: Cannot use 'in' operator to search for 'originalError' in null
    at new Eip838ExecutionError (root\node_modules\web3-errors\src\errors\contract_errors.ts:163:21)
    at new ContractExecutionError (root\node_modules\web3-errors\src\errors\contract_errors.ts:225:3)
    at Function._isReverted (root\node_modules\web3-core\src\web3_request_manager.ts:432:48)
    at Web3RequestManager._processJsonRpcResponse (root\node_modules\web3-core\src\web3_request_manager.ts:361:35)
    at Web3RequestManager.<anonymous> (root\node_modules\web3-core\src\web3_request_manager.ts:206:16)
    at Generator.next (<anonymous>)
    at fulfilled (root\node_modules\web3-core\lib\commonjs\web3_request_manager.js:21:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Environment

npm - 9.8.1
node - 18.17.1
web3 - 4.1.1
OS - Windows 10

Metadata

Metadata

Assignees

Labels

4.x4.0 relatedBugAddressing a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions