0

I am trying to compile the following contract. I am using Remix IDE. It is giving me infinite error in the Withdraw method.

    pragma solidity ^0.4.24;

     contract financialContracts4{

     address issuer; constructor() public{    issuer = msg.sender; }
     modifier ifIssuer(){    if(issuer != msg.sender){
           revert();    }else {
             _;//underscore    } } 
function receiveFunds( )public payable{
         } 
function getValue() public view returns(uint) {   address myAddress = this; return myAddress.balance; } 
function withdrawFunds(uint funds) ifIssuer{   issuer.transfer(funds); } }

The error message is:

Gas requirement of function financialContracts4.withdrawFunds(uint256) high: infinite. If the gas requirement of a function is higher than the block gas limit, it cannot be executed. Please avoid loops in your functions or actions that modify large areas of storage (this includes clearing or copying arrays in storage) is:

Some body please guide me.

Zulfi.

2 Answers 2

0

Remix is complaining because it has no way of knowing how much gas the call takes.

Sending Ether to another contract (you can't know whether the issuer is a contract or an EOA (externally owned account)) allows the receiver to trigger their fallback function. And that function may do all sorts of logic. Gas for that logic is paid by the same transaction. As Remix can't know what logic the other end has it warns you that it may go over the gas limit.

This is typically not a real problem as you are only allowing the issuer to withdraw the funds so the issuer has to pay for all of that gas. So you can probably just ignore the warning.

-1
pragma solidity ^0.4.24;

contract financialContracts4{

address issuer; 
constructor() public{    
        issuer = msg.sender; 
    }

modifier ifIssuer(){ 
    if(issuer != msg.sender){
        revert();
    }else {
        _;//underscore    
    } 
}

function receiveFunds( ) public payable{} 

function getValue() public view returns(uint) {   
    address myAddress = this; 
    return myAddress.balance; 

    } 
function withdrawFunds(uint funds) ifIssuer public {   
    issuer.transfer(funds); 
    } 
}

The code that you've submitted is working fine. Didn't see any issue. are you trying on Remix ?

2
  • But I am getting 'infinite gas' warning. I am displaying the message also.Yes I am trying on Remix IDE.
    – zak100
    Nov 25, 2018 at 14:01
  • Infinite gas warning means, in the Remix env, “Warning: I’m not able to estimate the gas consumption in this part of the code. Please double check that code in order to be sure that it does what you need and expect!”. Nothing more.
    – Rick Park
    Jan 6, 2020 at 11:15

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.