I am interested in writing a simple application that emits events for notifications when a certain piece of data in the smart contract changes. These events do not need to persist, they can be fleeting and if a user misses one, it is not important, so they do not need to be logged.
Here is a sample smart contract with a basic event that is emitted in the setText
function. What would I change to make the event NOT logged, and therefore not taking up disk space somewhere?
contract HelloWorld {
string public text = "Hello World";
event NewText(
string _text
);
constructor() {
// Do nothing
}
function setText(string memory _text) public {
text = _text;
emit NewText(_text);
}
}
Or is there some better way to achieve what I'm going for?
events do not take up space in your contract. That is why it is cheaper than using a state variable.
Hashes of events are stored in the logsBloom
which is stored in the header of each block.
logs itself stored in the transaction receipt
which are stored in a trie and head of this trie is also stored inside the block header.
You can read this article: data-transaction-receipt-trie-and-logs-simplified
Logs are used to store information that is not required by the contract
When the smart contract wants to log data for the aforementioned scenarios, it can emit an event which is then written to the transaction receipt’s log records. Each transaction has only one transaction receipt. In addition to log records, the receipt includes status, gas used, and logs bloom
with 100% certainty, I would say no. In Ethereum everything is recorded