我正在学习nft智能合约是如何工作的。我不明白为什么发出事件会收到address(0)
。
这是Openzeppeling ERC721 的_mint函数
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
// i am stuck at here
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId);
}
当我们发出Transfer事件时,为什么要使用address(0)
。address(0)
代表空地址。这是转移事件:
event Transfer(
address indexed from,
address indexed to,
uint256 indexed tokenId);
在ERC-721标准(被认为是第一个NFT标准(中定义了在铸造令牌时传递零地址作为发送方参数:
/// @dev This emits when ownership of any NFT changes by any mechanism. /// This event emits when NFTs are created (`from` == 0) and destroyed /// (`to` == 0). Exception: during contract creation, any number of NFTs /// may be created and assigned without emitting Transfer. At the time of /// any transfer, the approved address for that NFT (if any) is reset to none. event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);