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.

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!
    – doswelleth
    Oct 30 at 8:19

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.