2

getting this error

Error: Transaction reverted: function returned an unexpected amount of data
at Proxy.getDecimals (contracts/proxy.sol:100)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

when using hardhat (forked mainnet/testnet). I am trying to read from a basic function decimals() of WETH.

My implementation is like this

interface ERC20 {
      function decimals() external returns (uint8); 
}

contract Proxy {
      function getDecimals(address _addr) external returns (uint8){
              return ERC20(_addr).decimals();
      }
}
1
  • can you share the code where you're calling the function? Commented Mar 31, 2023 at 4:41

1 Answer 1

0

It is due to the decimals() being a non-view function, it should be marked as view function. Try updating your ERC20 interface like this:

interface ERC20 {
    function decimals() external view returns (uint8);
}

Same for getDecimals function.

Also, ensure that the contract you call implements decimals() function, if not you may encounter this error as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.