1

I am trying to refer to this Solidity Docs https://solidity.readthedocs.io/en/v0.6.2/control-structures.html and trying to execute the following code

pragma solidity >=0.4.0 <0.7.0;

contract InfoFeed {
    function info() public payable returns (uint ret) { return 42; }
}

contract Consumer {
    InfoFeed feed;
    function setFeed(InfoFeed addr) public { feed = addr; }
    function callFeed() public { feed.info{value: 10, gas: 800}(); }
}

I am getting the following error

Expected ';' but got '{' function callFeed() public { feed.info{value: 10, gas: 800}(); } after info

This is the current version of docs and didnot expect to get this errors. Thank you for the help in advance

1

Your syntax is incorrect for any older compiler. It looks like it works only for version 0.6.2 and beyond.

Here's the right syntax for the line with any not-the-latest-compiler:

feed.info.value(10).gas(800)(); 

Typically you don't want to specify and special gas limit for an internal transaction so just leave that part out and it will just use whatever gas is left.

Also I strongly recommend to indent your code properly. It helps for readability and for detecting errors. So here's the indented version:

pragma solidity >=0.4.0 <0.7.0;

contract InfoFeed {
    function info() public payable returns (uint ret) { 
        return 42;
    }
}

contract Consumer {
    InfoFeed feed;
    function setFeed(InfoFeed addr) public { 
        feed = addr;             
    }
    function callFeed() public { 
        feed.info.value(10).gas(800)();             
    }
}
| improve this answer | |
  • Thank you for the help. It seems that the syntax I posted only works for compliers with 6.2+ commits only. So is there a way to send gas with such contract calls or they are not recommended. I really want to send the gas value with the call if it is possible – Hackeerrrr Feb 3 at 12:58
  • I wasn't even aware of the brand new syntax, thanks for the heads-up! You can provide the same data with the syntax I gave you. Edited answer. – Lauri Peltonen Feb 3 at 13:12
  • Yes, it works great. I was just curious if is there a way to send gas value with function calls or not – Hackeerrrr Feb 3 at 13:17
  • I'm not sure if I understand you correctly. You can supply the amount of gas in the old syntax with .gas(number) as I stated in my answer. If you don't provide that argument then all remaining gas is forwarded. – Lauri Peltonen Feb 3 at 13:20
  • Ah, I see. My bad. Sorry for the trouble. So I believe the receiving function must be payable in order to send a gas value – Hackeerrrr Feb 3 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.