I’m diving into NFT smart contracts and I’m confused about something in the minting process. Why does the Transfer event use address(0) as the ‘from’ address when minting a new token?
Here’s a simplified version of what I’m looking at:
function mintToken(address recipient, uint256 tokenId) internal {
require(recipient != address(0), "Can't mint to zero address");
require(!tokenExists(tokenId), "Token already exists");
balances[recipient] += 1;
tokenOwners[tokenId] = recipient;
emit TokenCreated(address(0), recipient, tokenId);
}
event TokenCreated(address indexed source, address indexed destination, uint256 indexed tokenId);
I get that address(0) is like an empty address, but why use it here? Is it because the token is new and didn’t come from anywhere? It just feels weird to me. Can someone help me understand the logic behind this?