-1

what is difference between transfer event of Mint function and Transfer function of ERC20 Smart Contract ?

I know that in Transfer event of Mint a from address is address(0) while in Transfer there is address of sender but not zero. I am expecting a different approach.

1 Answers1

0

The Transfer event accepts 3 params: token sender, recipient, and amount.

A token contract which creates new tokens SHOULD trigger a Transfer event with the _from address set to 0x0 when tokens are created.

Source: https://eips.ethereum.org/EIPS/eip-20

This is the standardized approach to emitting events when minting tokens.

You can also emit custom events on top of that. For example:

event Transfer(address indexed from, address indexed to, uint256 amount);
event Mint(uint256 amount, uint256 timestamp);

function mint(uint256 amount) external onlyOwner {
     balanceOf[msg.sender] += amount;
     totalSupply += amount;
     emit Transfer(address(0x0), msg.sender, amount);
     emit Mint(amount, block.timestamp);
}
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100