This question already has an answer here:

I've recently started with Solidity and like to know about the emit event as I wasn't sure of why it is being used in the program.

contract MyToken {

    string public name;
    string public symbol;
    uint8 public decimals;

    mapping (address => uint256) public balanceOf;

    event Transfer(address indexed from, address indexed to, uint256 value);

    /* Send coins */
    function transfer(address _to, uint256 _value) public {
        require(balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]);
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(msg.sender, _to, _value);

   constructor(uint256 initialSupply, string memory tokenName, string memory tokenSymbol, uint8 decimalUnits) public {
        balanceOf[msg.sender] = initialSupply;              
        name = tokenName;                                   
        symbol = tokenSymbol;                               
        decimals = decimalUnits; 



marked as duplicate by Ismael, Richard Horrocks, Jesse Busman, Achala Dissanayake, shane Dec 14 '18 at 3:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


emit is used to emit any events. Events are the way to notify the transaction initiator about the actions performed by the called function. It stores its emitted parameters in a certain log history and they can accessed outside the contract with some filter parameters. As per the solidity documentation:

Events are inheritable members of contracts. When you call them, they cause the arguments to be stored in the transaction’s log - a special data structure in the blockchain. These logs are associated with the address of the contract, are incorporated into the blockchain, and stay there as long as a block is accessible.

For more: What is an Event?

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