When I started learning Solidity I saw Event/Log functionality. After a little bit of research, it got me a little confused.
As far as I understand Event/Log (I use these words interchangeably because many resources use like that) was created for adding "some" data to transactions (Like web2 we used logs for debugging or sometimes easily find what happened specific event time and etc ).
But the interesting part is on the Front End side we can listen to this Log/Event and even we can use these logs for easy access data. (for example easy search by event topic) (we don't do it generally in web2)
Also, it's a cheaper version of storing something in the blockchain and for some reason I don't understand, other contracts or even same contract do not have access to these logs.
So my question is, what was the motivation behind creating events/logs in Solidity and is using logs in Front End somehow cheating or one of the motivations for creating Events?
If this is not motivation, are there any other alternatives for it?
Extra note: If you know why we can't access Log from Smart Contract or why it is cheaper to use Event/Log feel free to comment
Similar and relative questions in the platform.
- Can anyone explain what is the main purpose of events in solidity and when to use it? - Not verified answer and respondents only talked about how they use it on a daily basis which is I already mentioned this use cases in my question
- Why is storing via sstore more expensive than via events mechanism? - In this question verified answer says EVM nodes are not required to keep logs forever and can garbage collect old logs to save space So if I understand correctly nodes can delete logs from the machine if need extra space.
- https://blog.qtum.org/how-solidity-events-are-implemented-diving-into-the-ethereum-vm-part-6-30e07b3037b9 - In this blog says The reason that a log operation is cheap is because the log data isn’t really stored in the blockchain. Logs, in principle, can be recalculated on the fly as necessary. I'm not sure this blog is correct because I think logs added to the transaction and transactions stored inside block. So this is mean logs also in blockchain :/
- Why can't smart contracts access events - In there verified answer little bit more interesting than the other ones. It's says Logs were intended to be purgeable i.e. full nodes have logged only for X years - this is why the gas cost is lower. Which makes sense, but what if any node don't store this log data, but when the client searches for this log? It will be calculated via node somehow? I assume logs exist somewhere in blockchain. But answer also continue Because logs may or may not be there, they cannot be accessed from the state that needs to be deterministic So is this mean log not store inside blockchain or it's hard to calculate?