0

I'm trying to deploy a trivial faucet program which compiles OK with remix but I get the following error. "Gas requirement of function Faucet.withdraw(uint256) high: infinite. " This means that while it compiles I cannot deploy it to my Ganache blockchain. I understand the concept of gas for a function but I cannot see what is potentially infinite here: I have put a tiny limit on any withdrawal amount.

Could someone please explain?

pragma solidity >=0.5.0;

contract Faucet {

    function withdraw(uint256 withdraw_amount) public   {    
        require(withdraw_amount <= 2000000);
        msg.sender.transfer(withdraw_amount);
        }

    // Accept any incoming amount
    function () external payable {}
}

1 Answer 1

0

Gas requirement of function Faucet.withdraw(uint256) high: infinite.

Thisis a misleading warning caused by the require(). It can be safely ignored.

This means that while it compiles I cannot deploy it to my Ganache blockchain

Not true. You can deploy it.

pragma solidity >=0.5.0;

In my opinion, this is bad form except in librarys and inheritable contracts. You do indeed have a problem with 0.6.x and above because the fallback syntax is changed from an unnamed function to an explicitly named fallback() function.

One cannot know what breaking changes will be introduced in the future, so top-level contracts (to deploy) should indicate precisely what compiler to use. One can safely use ^ and >= for inherited modules that will not be deployed on their own.

I did not know what you used because it is ambiguous. However, I can see that it compiles and deploys with 0.5.16, and it does not with 0.6.x so ...

pragma solidity 0.5.16;

contract Faucet {

    function withdraw(uint256 withdraw_amount) public   {    
        require(withdraw_amount <= 2000000);
        msg.sender.transfer(withdraw_amount);
        }

    // Accept any incoming amount
    function () external payable {}
}

Hope it helps.

2
  • You're dead right about the pragma, it's a stupid error. I did comment out the require() but Remix still says the gas supply is infinite; if I comment out msg.sender.transfer line it stops the error but. of course, makes the function useless.
    – DavidH
    Feb 24, 2020 at 9:50
  • That sounds like trying to send more money than the contract has. Feb 24, 2020 at 14:26

Your Answer

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

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