This code is inside a view function and gives the error : Function declared as view but this potentially modifies state.

if ( auction.iS == false){      //check if such auction exists
emit NoSuchAuction(msg.sender, _auctionName); 
return; }

NoSuchAuction() is an event. _auctionName is a string. auction is a structure and iS is a boolean.


Events take a place in the blockchain which can be filtered. But functionality of a view function cannot make any changes in the blockchain state. That's why you are getting the error. Use return, to get the parameters back, if event is required, remove the view from it. View & event cannot live together.

Know more about state change : http://solidity.readthedocs.io/en/latest/contracts.html?highlight=emit#view-functions

  • 1
    Thanks, I got rid of the event and put the bool in the return list. – Kuelf Deez Mar 10 '18 at 12:21
  • 1
    Great, if this is solved, please accept the right answer to help the community. Thanks – Aniket Mar 10 '18 at 12:24

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.