1

I am trying to compile a simple contract on Remix but I am getting following 3 warnings:

  1. Gas requirement of function Greeter.hello() 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)
  2. Gas requirement of function Greeter.set(string) 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)

  3. Gas requirement of function Greeter.yourName() 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)

The contract is given below:

pragma solidity ^0.4.22;

contract Greeter {
   string public yourName;
   constructor() public{
      yourName = "World";
   }
   function (string name) public {
      yourName = name;
   }
   function hello( ) public constant returns (string) {
      return yourName;
   }
}

Some body please guide me how to remove the above warnings.

Zulfi.

1 Answer 1

3

All those warnings are correct. You asked how to "remove" them, but I think that's the wrong approach. They're there because you're manipulating strings, and there's no way to know how long those strings will be, so there's no way to know how much gas could be consumed manipulating them.

You could use something other than strings, e.g. bytes32 (which can roughly be used to store up-to 32-byte strings), but why? If the reason is just "to silence a warning," then I think you may be misunderstanding the purpose and value of warnings.

1
  • Thanks. I got them removed by using bytes32 instead of string everywhere in the contract. Thanks for your answer and for another post on this forum which says the same.
    – zak100
    Nov 6, 2018 at 0:06

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.