ethers.js
ethers.js copied to clipboard
Sometimes I get an error could not decode result data (value="0x",
Ethers Version
"ethers": "^6.1.0"
Search Terms
network
Describe the Problem
Sometimes I get an error when making a contract call and when the contract call ends.
GetFeesToCollectError: could not decode result data (value="0x", info={ "method": "collect", "signature": "collect((uint256,address,uint128,uint128))" }, code=BAD_DATA, version=6.1.0) GetPositionsError: could not decode result data (value="0x", info={ "method": "positions", "signature": "positions(uint256)" }, code=BAD_DATA, version=6.1.0)

Code Snippet
this.NonfungiblePositionManagerContract.tokenOfOwnerByIndex(
this._addressAccount,
BigInt(i)
)
.then((tokenId: bigint) => {
this.dispatch(updateTokensIdsOfNFT(tokenId));
})
.catch((error: any) => {
console.log(`GetTokenOfOwnerByIndex` + error);
});
Contract ABI
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "uint256",
"name": "index",
"type": "uint256"
}
],
"name": "tokenOfOwnerByIndex",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
Errors
could not decode result data (value="0x", info={ "method": "tokenOfOwnerByIndex", "signature": "tokenOfOwnerByIndex(address,uint256)" }, code=BAD_DATA, version=6.1.0)
Environment
Browser (Chrome, Safari, etc)
Environment (Other)
No response
Attach screenshot
Sometimes the call appears to return 0, as if the RPC call is still in the background and resolved at the same time
I made implemented a recursive retry on catch with wrapping inside function promise. Cant determine when happening, it's random and appears with all contracts
Can you determine which Provider is being used? Could it be a specific provider within the FallbackProvider is no co-operating or returning weird responses?
mainnet.infura.io/v3/ It seems that it also happens in other applications that are not mine. For example, the one I'm using as a base as uniswap
I am seeing the same issue using the default provider (ethers.getDefaultProvider(url)) and the JsonRpcProvider. This is happening when calling a simple get() function in the smart contract that returns a uint256 value stored in the contract (nothing exotic).
me to
I think I have seen this issue with Alchemy previously. eth_call returns "0x" randomly and it's also not a json rpc error. Ethers v5 treat it as a call exception.
To confirm if this is actually a problem, can you try a solution similar to this? Does it reduce these errors?
class JsonRpcProviderRetry extends JsonRpcProvider {
// if result is 0x then it retries it 4 times
async call(_tx: TransactionRequest): Promise<string> {
let result: string;
for (let i = 0; i < 4; i++) {
result = await super.call(_tx);
if (result !== "0x") break;
}
return result!;
}
}
(A better solution could be to only retry if expected non-empty return data).
Same Error.
Function returning a "internalType": "uint256[]" and no argument in input.
ABI
{
"inputs": [],
"name": "getMintedTokenId",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
Provider is JsonRpcProvider, but no issue when using metamask BrowserProvider.
this issue is probably a duplicate of #3826 but the cause reason explain in this issue..different network.. is not the cause.
I had exctly this problem today: since the provider is BrowserProvider, it dictates in which network your contract ABI belongs to.
In other words, when you do...
new ethers.Contract(contractAddress, abi, new ethers.BrowserProvider(window.ethereum))
...it is not mentioned the network that you are connected to, so the provider implicitly selects this.
In my case, I am using Celo Alfajores.
It requires you to switch the network within the provider (in my case, Metamask). This is twice more anoying if both protocols operates the same way because no extra error is displayed.
This forced me to do two things:
- check if the provider for the network is the same as my contract deployment.
- add a listener for the provider being changed.
If you are using a third party provider, please reference the ethers.getDefaultProvider(url) mentioned. If your provider doesn't responde with the information about your network, it might break as well.
I'm creating a PR for changing the message for this error. It is not a "parse" error, as it leads to be. Its a 404 on that network, despite the ABI being valid.
Same issue here. (with JsonRpcProvider)
I was trying to just load balanceOf, decimals, symbol of ERC20 token on Sepolia and it's always fails while on Linea it works correctly.
UPD: just check out your network in Metamask :)
I am getting the same, error just trying to fetch some data from my deployed contracts.