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

Sometimes I get an error could not decode result data (value="0x",

Open Cazs03 opened this issue 2 years ago • 13 comments
trafficstars

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)

image

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

Cazs03 avatar Mar 15 '23 06:03 Cazs03

Attach screenshot image Sometimes the call appears to return 0, as if the RPC call is still in the background and resolved at the same time

Cazs03 avatar Mar 16 '23 14:03 Cazs03

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

Cazs03 avatar Mar 17 '23 05:03 Cazs03

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?

ricmoo avatar Mar 18 '23 17:03 ricmoo

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

Cazs03 avatar Mar 20 '23 06:03 Cazs03

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).

jiaochangyang avatar Apr 11 '23 03:04 jiaochangyang

me to

Quietly-20201113 avatar Apr 24 '23 16:04 Quietly-20201113

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).

zemse avatar Apr 25 '23 08:04 zemse

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.

ohrrkan avatar May 05 '23 13:05 ohrrkan

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.

image

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.

dav1app avatar May 30 '23 16:05 dav1app

Same issue here. (with JsonRpcProvider)

emretepedev avatar Jun 20 '23 18:06 emretepedev

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 :)

Solniechniy avatar Sep 05 '23 11:09 Solniechniy

I am getting the same, error just trying to fetch some data from my deployed contracts.

PratikJasl avatar Dec 06 '23 17:12 PratikJasl