2

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.

1 Answer 1

5

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
  • 1
    Thanks, I got rid of the event and put the bool in the return list.
    – Kuelf Deez
    Mar 10, 2018 at 12:21

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.