I have found some code samples for "burn function" on token contract. In this function, burn amount is substracted from the balance and then "Transfer Event" is emit to address 0. Why the event is emit, what is the function of that. If emitting isn't executed, would gas fee reduced for the "burn function"?
1 Answer
Events can be thought of as logs written in the blocks. It is useful for off-chain services that can subscribe to these events and take action. As they modify the storage, events increase (slightly) the gas cost of the transaction (more info here : How do events influence a transaction's gas?).
A burn
usually emits a Transfer
event with the recipient being the zero address. But this is purely conventional because there is no transfer at all to the zero address (its balance does not increase). Moreover the ERC20 standard does not specify the burn
mechanism.
Using address 0 as the recipient helps off-chain services detect that tokens have been burned.