Let's say I have a very simple contract:
contract basicStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint) {
return storedData;
}
}
I would like to watch for changes on set() which I believe changes the contracts state, is it possible using filter/watch in web3.js?
Best Answer
I would recommend to use events.
Smart-Contract - Log events
The code above logs an event each time the function
set(x)
is executed. The log contains the sender address and the argument x.Web3 - Watch events
This code compiles the contract and retrieves an
myEvent
object which can be used to watch for an event (in our case that represents a state change).Then sends two transactions and check if some logs are printed.
Result
You can find more info
Solidity doc
Web3 doc