ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

BAD_DATA error when result has '0x'

Open vivekfyi opened this issue 2 years ago • 9 comments

Ethers Version

6.0.3

Search Terms

BAD_DATA

Describe the Problem

when calling a newly deployed contract method getting following error:

Error: could not decode result data (value="0x", info={ "method": "owner", "signature": "owner()" }, code=BAD_DATA, version=6.0.3)

Following is debug logs:

[
  { jsonrpc: '2.0', id: 1, result: '0x14a33' },
  { jsonrpc: '2.0', id: 2, result: '0x' },
  { jsonrpc: '2.0', id: 3, result: '0x14a33' }
]

Code Snippet

No response

Contract ABI

No response

Errors

No response

Environment

No response

Environment (Other)

No response

vivekfyi avatar Feb 24 '23 05:02 vivekfyi

Can you make sure you update to the latest version (6.0.8) first? And then if you still have the problem, include a short demo script the reproduces the issue?

ricmoo avatar Feb 24 '23 06:02 ricmoo

Can you make sure you update to the latest version (6.0.8) first? And then if you still have the problem, include a short demo script the reproduces the issue?

I am getting the same BAD_DATA error when the view function is returning a tuple: (bool, CustomEnum). I've tried updating to 6.0.8, but this breaks my typescript build, with the error:

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("ethers")' call instead.

Using the following tsconfig.json:

{
  "include": ["src", "types"],
  "compilerOptions": {
    "outDir": "dist",
    "target": "es2020",
    "module": "commonjs",
    "moduleResolution": "node16",
    "skipLibCheck": true,
    "importHelpers": true,
    "declaration": true,
    "sourceMap": true,
    "strict": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "experimentalDecorators": true
  }
}

The view function is verifying a signature, and returning a tuple.

froggiedev avatar Mar 01 '23 00:03 froggiedev

Note: I am currently using 6.0.4 and any version above has the same typescript issue.

froggiedev avatar Mar 01 '23 01:03 froggiedev

Turns out the BAD_DATA was caused by querying the contract on the wrong chain. Still not sure about the typescript issue.

froggiedev avatar Mar 01 '23 01:03 froggiedev

@froggiedev It sounds like maybe you are missing a "type": "module" in your package.json?

ricmoo avatar Mar 07 '23 07:03 ricmoo

[RESOLVED] facing similar issue, when making a call to view function like below

const owner = await testContract.owner();

Error:

Error: could not decode result data (value="0x", info={ "method": "owner", "signature": "owner()" }, code=BAD_DATA, version=6.2.0)```

heypran avatar Mar 26 '23 11:03 heypran

@heypran Can you include the contract address and network?

ricmoo avatar Mar 26 '23 12:03 ricmoo

After hour of debugging, I realized the HRE was using different network deploying one of the contract, rest were deployed correctly. Its working now. Sorry to bother.

heypran avatar Mar 26 '23 16:03 heypran

After hour of debugging, I realized the HRE was using different network deploying one of the contract, rest were deployed correctly. Its working now. Sorry to bother.

Hi, can u give me some detailed solution? I am facing same problem but still not solved this

fukemy avatar Aug 21 '24 07:08 fukemy