Consider the following snippet from an ERC-721 contract. What event is emitted when _mint is called?
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); function _mint(address to, uint256 tokenId) internal { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); }
Minting a token means creating it from nothing, so the 'from' address is zero.
When minting a new token, the Transfer event is emitted with the from address set to zero to indicate creation. The to is the recipient address.
Given this sequence of calls on an ERC-721 contract, what is the balance of 0xABC after all operations?
function _mint(address to, uint256 tokenId) internal {
_balances[to] += 1;
_owners[tokenId] = to;
}
function _transfer(address from, address to, uint256 tokenId) internal {
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
}
// Sequence:
// _mint(0xABC, 1);
// _mint(0xABC, 2);
// _transfer(0xABC, 0xDEF, 1);Think about how many tokens 0xABC owns after minting two and transferring one away.
0xABC mints two tokens, so balance is 2. Then transfers one token away, so balance decreases by 1, resulting in 1.
Examine this transfer function snippet. Why does it revert when called?
function transferFrom(address from, address to, uint256 tokenId) public { require(_owners[tokenId] == from, "Not token owner"); require(to != address(0), "Transfer to zero address"); _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; }
Think about who is allowed to call transferFrom in ERC-721.
ERC-721 requires that the caller is owner, approved, or operator. This code lacks that check, so unauthorized calls revert.
Choose the correct Solidity code for supportsInterface that returns true for ERC-721 interface ID 0x80ac58cd and calls super otherwise.
Remember the logical OR operator returns true if either side is true.
The function must return true if the interfaceId matches ERC-721's ID or if the parent contract supports it. Option A correctly uses || operator.
Given this ERC-721 contract snippet and sequence, what is the final balance of 0x123?
mapping(address => uint256) private _balances;
mapping(uint256 => address) private _owners;
function _mint(address to, uint256 tokenId) internal {
_balances[to] += 1;
_owners[tokenId] = to;
}
function _burn(uint256 tokenId) internal {
address owner = _owners[tokenId];
require(owner != address(0), "Token does not exist");
_balances[owner] -= 1;
delete _owners[tokenId];
}
function _transfer(address from, address to, uint256 tokenId) internal {
require(_owners[tokenId] == from, "Not owner");
_balances[from] -= 1;
_balances[to] += 1;
_owners[tokenId] = to;
}
// Sequence:
// _mint(0x123, 10);
// _mint(0x123, 20);
// _transfer(0x123, 0x456, 10);
// _burn(20);Track each token's ownership and balance changes carefully.
Initially, 0x123 owns tokens 10 and 20 (balance 2). Token 10 is transferred to 0x456 (balance 0x123:1). Token 20 is burned (balance 0x123:0). Final balance is 0.