0

This line of code changes state when a new owner is set, but remix still wants to me to mark the declaration with view, which reads from the contract.

Why is that?


pragma solidity ^0.8.7;

 function setOwner(address _newOwner) external onlyOwner {
        require(_newOwner != address(0), "invalid address");
        owner == _newOwner;
    }

View causes me to not be able to properly set (change) state.

1 Answer 1

0

This is not an error on solidity's side look, at your owner variable change :

owner == _newOwner;

I believe you meant to write :

 owner = _newOwner;

This meant your function was actually not changing the state in any way. So requiring it to be set to view is a perfectly valid recommendation.

1
  • This is correct! I can't believe I missed that. Accepted, but don't have 15 points yet! Commented Oct 30, 2021 at 8:19

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.