0

# Why does the Warning come up?


struct Owner {
        address owner;
        string ownerName;
        string petName;
        uint ownerprice;
        string petInfo;
        string petselltext;
        uint ownerwallet;
    }


    mapping (address => Owner) Owners;
    address[] public OwnerAddresses;

struct PetSitter {
        address petsitter;
        string petSittername;
        string petSitterInfo;
        string educationConfirm;
        string petsharetext;
        uint sitterprice;
        uint petsitterwallet;
    }

    mapping (address => PetSitter) PetSitters;
    address[] public PetSitterAddresses;


function PetSitterShareText(string _petsittertext, uint _sitterprice) public view returns(string) {
      //  var PetSitter = PetSitters[_sitter];
       PetSitters[msg.sender].petsharetext = _petsittertext;
       PetSitters[msg.sender].sitterprice = _sitterprice;

    }


    function OwnerShareText(address _OWNER, string _ownersharetext, uint _ownerprice) OwnerModifyInfo(_OWNER) public view  returns(string){
        Owners[msg.sender].petselltext = _ownersharetext;
        Owners[msg.sender].ownerprice = _ownerprice;

    } 

THis cryptozombies example code


function setMyNumber(uint _myNumber) public {
  favoriteNumber[msg.sender] = _myNumber;

}

  • Isn't the example the same as my code?
  • How do I change the Warning?

  • Waring is Function declared as view, but this expression (potentially) modifies the state and thus require non-payable (the default) or payable.

  • If I'm using View, can you do it without deleting View?

New contributor
samjamy is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

If you try to call the function, would probably fail.

The view modifier is read only and your functions are modifying storage (writing new variables).

It should probably be made to throw an error and not a warning

  • Is there only a way to remove the view? – samjamy Jan 12 at 16:43
  • depending on what soliditiy version you are using you can delete the view from the function. the contracts becomes more expensive but it would work – Data_Kid Jan 12 at 16:48

Your Answer

samjamy is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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