0

I am trying to run below code, but I receive this error

"Gas requirement of function Team3_SE427_Call.increaseCount is 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) Pos: 11:4:"

Here my code;

pragma solidity ^0.5.17;

contract Team3_SE427_Call{
    
    address payable constant CONTRACT_ADDRESS = 0x600cA6ef0678a82ac4ccbcd4BBc4b284D413C8a9;
    
    constructor() public payable {
        
    }
  
    function increaseCount() public payable {
        Team_SE427_Contract x = Team_SE427_Contract(CONTRACT_ADDRESS);
        int count = x.getCount.value(0.1 ether)();
        x.IncreaseCount.value(0.5 ether)(count);
    }
}

contract Team_SE427_Contract{
    function IncreaseCount(int predict) public payable;
    function getCount() public payable returns(int);
    
}

How can I fix the problem?

1 Answer 1

1

The problem is that the gas estimator does not have the source code for the contract Team_SE427_Contract and therefore it has no idea what happens when you call it. And therefore it can't estimate the required gas.

You have two options:

  1. Give a gas limit for the call to the contract Team_SE427_Contract. Can be done with something like this: int count = x.getCount.value(0.1 ether).gas(gasAmount)();. Naturally you have to know how much you should give gas to the contract so you have to be very sure how the contract is implemented

  2. If you're unsure how the contract is implemented you can give it a lot of gas and hope it's not malicious so that it doesn't eat all your gas.

Otherwise, the warning you are seeing is only a warning: the transaction will probably go through if you give the transaction high enough of gas limit.

1
  • Going with option 1. Where would you put this code for the Gas estimator to capture this?
    – SirBT
    Jun 15, 2022 at 11:38

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.