1

I've read somewhere says storing values in logs is cheaper than storing it in the contract's permanent storage. I wondered if it is the case. If yes, why?

More general question: What is the pros and cons of storing a value in a log and storing them in a variable?

1 Answer 1

1

PRO

Cheaper: Logs cost 375 gas for a LOG operation. 375 gas for each topic. 8 gas for each byte of a LOG operation's data. While contract storage costs 20,000 gas for each 32 bytes. See the yellow paper.

CON

Although logs offer gargantuan gas savings, logs are not accessible from any contracts unlike storage. Logs are meant to facilitate communication between smart contracts and their user interfaces, not between contracts.

Highly recommended for further reading.

2
  • Thanks for the answer. Why is storing a value in logs cheaper?
    – Aydin
    Sep 30, 2017 at 14:50
  • I guess the reason is that logs are not part of the blockchain itself per se, since they are not required for consensus (they are just historical data), however they are verified by the blockchain as the transaction receipt hashes are stored inside the blocks. Check these answers out: ethereum.stackexchange.com/questions/1302/… Sep 30, 2017 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.