Basically is it possible for constant functions to emit events? Example bellow:
I have Sample Contract which has a getData() function which does not modify any state, emits an event and returns a string value.
contract Sample {
event ExampleEvent(string data_description);
function getData() public constant returns (string) {
ExampleEvent("From Sample contract");
return "Event sent";
}
}
Then I try to call it through nodejs with web3.js using .call()
(this does not emit event)
SampleContract(abi).at(address).getInfo.call({from:{account});
I only receive the "Event sent" string as a response, but no event has been created.
However if I call this function via a transaction .sendTransaction()
(this emits event)
SampleContract(abi).at(address).getInfo.sendTransaction({from:{account});
This returns the transaction hash as expected (since I'm creating a transaction) but it also creates a new event.
I understand that constant functions cannot change a contract state however a new event is not really part of the contract storage/state (events/logs are stored in the transaction logs)?
What is the reason for this not to be working, am I missing something obvious?