1

I can't work out how to modify this...When I change pure to view I get a different error:

function balanceOf(address _owner) public pure returns (uint256 balance) {
    return balances[_owner];
}

changing to view gives this error:

Overriding function changes state mutability from "pure" to "view".
    function balanceOf(address _owner) public view returns (uint256 balance) {
    ^
Spanning multiple lines.
  • 1
    Is balanceOf overriding a parent function of the same signature with the state mutability "pure"? An erc20 balanceOf function definitely shouldn't be pure because it needs to read balances from the state. – flygoing Jan 26 '18 at 18:29
  • 2
    Thanks for replying. I had a function further up that was pure, thanks!!! been looking at this for hours, its all blending together LOL – Matthew Hughes Jan 26 '18 at 18:36
  • 1
    I've got another error, unction declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. How would I change this? function coinAge() public view returns (uint myCoinAge) { myCoinAge = getCoinAge(msg.sender,now); } – Matthew Hughes Jan 26 '18 at 18:39
1

You're fine. Because you're reading a state variable with Blockchain data (ie the reserved keywords like tx, msg, and so on) it's giving you a compiler warning as the compiler is not smart enough to understand that you're not actually modifying anything.

Also make sure getCoinAge is also marked view. http://solidity.readthedocs.io/en/develop/miscellaneous.html?highlight=Pure

| improve this answer | |

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.