Search code examples
ethereum

functions Burn and Transfer source


so i was reading through this https://www.ethereum.org/token#minimum-viable-token article which is providing an example for an ethereum token with such functionalities as transferring and burning coins. Lets take a piece of code:

function burn(uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value);   // Check if the sender has enough
        balanceOf[msg.sender] -= _value;            // Subtract from the sender
        totalSupply -= _value;                      // Updates totalSupply
        Burn(msg.sender, _value);
        return true;
    }

everything is pretty clear to me here, we take coins from sender, then take it from the total supply, but what's with line:

        Burn(msg.sender, _value);

Where does this function come from? what it does which wasnt done already?


Solution

  • It's publishing an event, declared earlier in the code:

    // This notifies clients about the amount burnt
    event Burn(address indexed from, uint256 value);
    

    Here's a blog post I wrote about events, including how they're monitored client-side: https://programtheblockchain.com/posts/2018/01/24/logging-and-watching-solidity-events/.