ethers.js
ethers.js copied to clipboard
BAD_DATA error when result has '0x'
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
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?
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.
Note: I am currently using 6.0.4 and any version above has the same typescript issue.
Turns out the BAD_DATA was caused by querying the contract on the wrong chain. Still not sure about the typescript issue.
@froggiedev It sounds like maybe you are missing a "type": "module" in your package.json?
[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 Can you include the contract address and network?
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.
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