3

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; greetings.push(_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

2

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.

4
  • 1
    what would u recommend using a fixed array ? Commented 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 Commented May 13, 2018 at 12:48
  • 1
    Yes, I think using a fixed array will solve it. Commented 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. Commented May 13, 2018 at 13:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.