0

I have a function

function tokenValue( address _token, uint _amount ) public view returns ( uint ) {
        return _amount.mul( 10 ** IERC20( MY_TOKEN ).decimals() ).div( 10 ** IERC20( _token ).decimals() );
    }

To convert the decimals of one token into my token. However, when trying to call this on the deployed contract in a hardhat console, I get this error

  reason: 'cannot estimate gas; transaction may fail or may require manual gas limit',
  code: 'UNPREDICTABLE_GAS_LIMIT',

In my hardhat.config I have a manual gas limit of 2100000 so I'm not sure what I'm doing wrong here.

1 Answer 1

0

Due to this closed issue solution approach comment https://github.com/ethers-io/ethers.js/issues/1232#issuecomment-853726035 about UNPREDICTABLE GAS LIMIT problem, you have to remove gasPrice from your payloads to simplify eth_estimateGas.

Polygon also is sometimes returning 0 from estimation gas without no clue why which may also lead to problems UNPREDICTABLE GAS LIMIT.

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.