I'm getting the warning

Gas requirement of function helloWorld.getGreeting() 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)

in the following contract

pragma solidity ^0.4.22;

contract helloWorld {

    string public greeting; 

    string[] public greetings;

    constructor() public {
        greeting = 'hello World';
        greetings.length= greetings.length + 1;

    function setGreeting(string _newGreeting) public {
        greeting = _newGreeting;

    function getGreeting() public view returns (string) {
        return greeting;

I would like to be able to have the contract with none of these warnings, any help would be great !

thanks in advance !

1 Answer 1


The issue is that you are using dynamic arrays (i.e, string). Remix cannot know "a priori" the length of these variables, therefore this function has the potential of requiring a lot of gas.

  • 1
    what would u recommend using a fixed array ?
    – conwise17
    May 13, 2018 at 12:30
  • 1
    do you know of any documentation that would help understand more of this warning in particular ? thanks in advance
    – conwise17
    May 13, 2018 at 12:48
  • 1
    Yes, I think using a fixed array will solve it.
    – Jaime
    May 13, 2018 at 13:49
  • 1
    I just did it quicky in remix, changing all your arrays, for instance, to bytes32 silence all the warnings about gas.
    – Jaime
    May 13, 2018 at 13:53

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.