ethers.js v6 (6.11.1 & 6.14.1) JsonRpcProvider.call() on Polygon incorrectly invokes ENS resolver logic, leading to BAD_DATA error #4994
Replies: 4 comments 3 replies
-
The reason is the address looks incorrect. Your address My guess is that you had a string address somewhere, and you used Let me know if that helps. :) |
Beta Was this translation helpful? Give feedback.
-
(moving to discussions) |
Beta Was this translation helpful? Give feedback.
-
Closing Issue: Resolved Contract Recognition Problem on Polygon (EIP-55 Checksum) Hi everyone, I'm pleased to announce that the issue encountered in our test script, which was preventing the correct recognition and interaction with our smart contract on the Polygon network, has been resolved! The error manifested with messages like "could not decode result data (value="0x", info={ "method": "resolver", ...})" and was due to a subtle, yet crucial, difference in how addresses are handled when they are not properly checksummed (EIP-55). The Root Cause: EIP-55 Checksumming vs. Case Sensitivity Initially, we suspected the error might be related to the address length (e.g., whether it had 40 or 42 characters including the "0x" prefix). While an incorrect length would certainly cause an error, the specific "could not decode result data" error with the resolver(bytes32) method pointed to a different underlying issue. The problem was that the address used in our script was in all lowercase characters (e.g., 0x6a6d5c29ad8f23209186775873e123b31c26e9). Although Ethereum addresses are case-insensitive at the blockchain protocol level, and completely lowercase addresses are technically valid, the EIP-55 checksum standard introduces a mix of uppercase and lowercase letters. This mixed-case formatting is not arbitrary; it serves as a checksum mechanism to help detect typos in addresses. Libraries like Ethers.js, when provided with a string that has the correct length and "0x" prefix but does not conform to the EIP-55 checksum format, will often interpret it as a potential ENS (Ethereum Name Service) name that needs to be resolved. This led Ethers.js to attempt calling a resolver() function, which then failed, causing the "could not decode result data" error because the address was neither a valid ENS name nor a properly checksummed address for direct contract interaction. The Solution: The solution was to ensure the contractAddress variable in our script used the exact EIP-55 checksummed address provided by PolygonScan. This address explicitly includes the correct mix of uppercase and lowercase letters. The correct and working address is: const contractAddress = "0x6a6d5Dc29ad8ff23209186775873e123b31c26E9"; |
Beta Was this translation helpful? Give feedback.
-
Closing Issue: Resolved Contract Recognition Problem on Polygon (EIP-55 Checksum) Hi everyone, I'm pleased to announce that the issue encountered in our test script, which was preventing the correct recognition and interaction with our smart contract on the Polygon network, has been resolved! The error manifested with messages like "could not decode result data (value="0x", info={ "method": "resolver", ...})" and was due to a subtle, yet crucial, difference in how addresses are handled when they are not properly checksummed (EIP-55). The Root Cause: EIP-55 Checksumming vs. Case Sensitivity Initially, we suspected the error might be related to the address length (e.g., whether it had 40 or 42 characters including the "0x" prefix). While an incorrect length would certainly cause an error, the specific "could not decode result data" error with the resolver(bytes32) method pointed to a different underlying issue. The problem was that the address used in our script was in all lowercase characters (e.g., 0x6a6d5c29ad8f23209186775873e123b31c26e9). Although Ethereum addresses are case-insensitive at the blockchain protocol level, and completely lowercase addresses are technically valid, the EIP-55 checksum standard introduces a mix of uppercase and lowercase letters. This mixed-case formatting is not arbitrary; it serves as a checksum mechanism to help detect typos in addresses. Libraries like Ethers.js, when provided with a string that has the correct length and "0x" prefix but does not conform to the EIP-55 checksum format, will often interpret it as a potential ENS (Ethereum Name Service) name that needs to be resolved. This led Ethers.js to attempt calling a resolver() function, which then failed, causing the "could not decode result data" error because the address was neither a valid ENS name nor a properly checksummed address for direct contract interaction. The Solution: The solution was to ensure the contractAddress variable in our script used the exact EIP-55 checksummed address provided by PolygonScan. This address explicitly includes the correct mix of uppercase and lowercase letters. The correct and working address is: const contractAddress = "0x6a6d5Dc29ad8ff23209186775873e123b31c26E9"; Using RPC URL (direct from .env): https:// |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Ethers Version
6.11.1 (also observed with 6.14.1)
Search Terms
ethers.js v6 polygon BAD_DATA resolver ethers.js polygon getResolver 0x ethers.js v6 contract call ens error polygon ethers JsonRpcProvider polygon ens issue ethers could not decode result data resolver
Describe the Problem
We are encountering a persistent
BAD_DATA
error (info:{ "method": "resolver", "signature": "resolver(bytes32)" }
,value="0x"
) when attempting to make a simpleview
function call (e.g.,name()
) to a deployed and verified smart contract on Polygon Mainnet (chainId 137) usingethers.JsonRpcProvider.call()
. This issue has been observed withethers
version 6.11.1 (after downgrading from 6.14.1), across different Node.js versions (v18.20.8 LTS, and previously v22.15.1), and using different Polygon RPC providers (QuickNode, public nodes likehttps://polygon-rpc.com
).The stack trace indicates that even for a direct
provider.call()
with a hex contract address and encoded calldata,ethers.js
internally attempts to useJsonRpcProvider.getResolver()
. This internal call to the RPC forresolver(bytes32)
(a standard ENS resolver function signature) apparently returns0x
, whichethers.js
then fails to decode as a valid resolver address, throwing theBAD_DATA
error. Direct provider calls likegetBlockNumber()
work correctly.This behavior is unexpected as no ENS names are being used for the contract interaction, and the target is always a valid hexadecimal contract address.
Link to Minimal Reproducible Test Case Repository:
https://github.com/avvstancamarcello/ethers_v6_polygon_issue_testcase
(The README.md in this repository contains the full environment details, contract information, steps to reproduce, and actual error outputs.)
Environment & Versions (summary, full details in linked README):
Contract Address (Polygon Mainnet):
0x6a6d5c29ad8f23209186775873e123b31c26e9
Steps to Reproduce (summary, full details in linked README):
https://github.com/avvstancamarcello/ethers_v6_polygon_issue_testcase
npm install
..env
with a Polygon RPC URL (as per.env.example
).node scripts/testEthersDirect.js
.Expected Result:
The script should successfully call the
name()
view function on the contract and print the contract's name.Actual Result:
The script successfully calls
provider.getBlockNumber()
but fails whenprovider.call()
is executed for thename()
function with theBAD_DATA
error related toresolver(bytes32)
. The full console output is in the README of the linked repository. Example message:Message: could not decode result data (value="0x", info={ "method": "resolver", "signature": "resolver(bytes32)" }, code=BAD_DATA, version=6.11.1)
Additional Context (summary, full details in linked README):
The core issue appears to be that
ethers.js
v6 incorrectly triggers ENS resolution logic even for direct hexadecimal addresses on Polygon. The RPC provider's0x
response to an internalresolver(bytes32)
-like query is then not handled gracefully, leading to theBAD_DATA
error. This makes basic view function calls unreliable under these conditions. We also observed aNotImplementedError: Method 'HardhatEthersProvider.resolveName'
when using Hardhat's ethers wrapper, indicating a broader theme of ENS/resolver related issues.Code Snippet
Contract ABI
Errors
Environment
node.js (v12 or newer)
Environment (Other)
Node.js versions tested: v22.15.1 and v18.20.8 (LTS). The issue persists on both. npm versions: v10.9.2 (with Node v22) and v10.8.2 (with Node v18). Operating System (WSL2): Ubuntu 22.04.5 LTS (running on Windows 11 Home). Full environment details and reproduction repository linked in the main description.
Beta Was this translation helpful? Give feedback.
All reactions