I wonder if there is a way to be notified of a potential contract state change (ie it has been part of a transaction) without having to use the event mecanism.

Say I have contract that can be modified across time and I want to be able to read their constant functions if I am notified that they were changed in a transaction.

I have created the following test case

contract Simple {
  uint public data; // a state field
  event Notify(uint newData);

  function setData(uint _data) { data = _data; }
  function setDataAndNotify(uint _data) { setData(_data); Notify(_data); }

And on the console side, create the contract, then subscribe to the NotifyEvent or if I subscribe to any event using the filter function as follow : (S is my contract instance variable)

S.Notify(function(e, log) { console.log("Notified ", log); })
web3.eth.filter({ address: S.address }, function(e, log) { console.log("Generic filter ", log); })

when I call the following, both notification are received (normal)

S.setDataAndNotify(1, web3.callinfo)

when I call the following, nothing get triggered on my callback.

S.setData(2, web3.callinfo)

But the transaction went through because the S.data() returns 2.

So is there a way to still receive a callback when the S.setData() transaction is called? I guess not but has anyone found a way (that does not imply checking after each new block with the filter('latest').


  • No answer here apparently. I guess it is not feasible. I consider there is a need to have an event log added to each function then. Anyone has a better suggestion? Commented Feb 20, 2017 at 6:18

1 Answer 1


In absence of better solution I propose the following pattern. Using a modifier to have all your state changing method trigger a simple small event. That would be the inverse of the "constant" keyword.

contract RootContract {
    event StateChanged();
    modifier modifies() {

contract Simple is RootContract {
  uint public data; // a state field
  event Notify(uint newData);

  function setData(uint _data) modifies { data = _data; }

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.