pragma solidity ^0.4.0;

contract CustodialContract{

    address client;
    bool public _switch = false;

    event UpdateStatus(string _msg);
    event UserStatus(string _msg, address user, uint amount);

    function CustodialContract(){
        client = msg.sender;

    modifier IfClient(){
        if(msg.sender !=client){

    function depositFunds() payable{
        emit UserStatus('User has deposited money!', msg.sender, msg.value);


    function withdrawFunds(uint amount) IfClient{
            emit UpdateStatus('User has transferred some money!');
            _switch = false ;

    function getFunds() constant returns(uint) {
        emit UpdateStatus('Someone called a getter!');
        return address(this).balance;

I know this is not a bug, but my inexperience with Solidity is the cause of this. Anyway, I want to fire off the UpdateStatus('Someone called a getter!'). I receive this error on the Solidity VM.

(browser/Untitled.sol:38:14: Warning: Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.)

I would like an explanation breaking down this error and suggestions on how to make the event fire.

1 Answer 1


The issue is that the function getFunds is defined as constant but it contain an event emission just change it to public:

 function getFunds() public returns(uint) {
        emit UpdateStatus('Someone called a getter!');
        return address(this).balance;

Hope this helps

  • Definitely helped thanks! I have to ask, is setting the function public or private good practice? Since just deleting the constant also allows the event to fire Commented Jun 10, 2018 at 8:11
  • Yes, these keywords define the visibility of the function, if you do not say anything it goes by default to public. If this answered your question please accept the answer.
    – Jaime
    Commented Jun 10, 2018 at 8:15
  • Heh sorry I forgot about the button. Commented Jun 10, 2018 at 8:16

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.