0
pragma solidity >=0.5.0 <0.7.0;
contract Example{
    uint256 public x=3;
    function setArr(uint256 y) public  returns(uint256){
    x=y;
    return getArr(x);
    }
    function getArr(uint256 z) public pure returns(uint256)
    {  return z; }
}
user61878
  • 67
  • 1
  • 3
  • sorry but i am not able to relate – user61878 Jul 29 '20 at 18:37
  • There are two types of functions those that do not change storage, ie view and pure, and those that modify it. The first group do not require to execute a transaction so you can obtain the returned value, the second group needs a transaction to modify storage so we cannot easily get the returned value (you need an archive node or a modified client like remix). In the question since function setArr modifies the contract storage, ie x is updated it has to be called in a transaction so no easy way to get the returned value. Read the linked for more details and alternatives. – Ismael Jul 29 '20 at 18:59
  • got it, so basically you are saying a function involving state change can return a value but should be avoided? the solution to this can be by creating a separate function(pure) which reads the value of x?Thank you so much,I really appreciate your help. – user61878 Jul 29 '20 at 19:05
  • It depends on the situation. It makes sense to have a return value if the function will be called from another contract. For user facing applications an event is usually better, but you can also have a view function to be called when the value is needed. – Ismael Jul 29 '20 at 20:21

0 Answers0