0
0
Blockchain / Solidityprogramming~20 mins

ERC-721 NFT standard in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ERC-721 Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this ERC-721 token URI function call?
Consider the following simplified Solidity function from an ERC-721 contract. What will be the output of tokenURI(1) if the base URI is set to "https://example.com/token/" and token 1 exists?
Blockchain / Solidity
string private baseURI = "https://example.com/token/";

function tokenURI(uint256 tokenId) public view returns (string memory) {
    require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
    return string(abi.encodePacked(baseURI, Strings.toString(tokenId)));
}

function _exists(uint256 tokenId) internal view returns (bool) {
    return tokenId == 1;
}
ARevert with error "ERC721Metadata: URI query for nonexistent token"
B"https://example.com/token/"
C"https://example.com/token/1"
D"https://example.com/token/0"
Attempts:
2 left
💡 Hint
Think about how the base URI and token ID are combined and what the _exists function returns.
🧠 Conceptual
intermediate
1:30remaining
Which function is required by the ERC-721 standard to transfer ownership of a token?
In the ERC-721 standard, which function must be implemented to allow safe transfer of a token from one owner to another?
Amint(address to, uint256 tokenId)
BtransferFrom(address from, address to, uint256 tokenId)
Capprove(address to, uint256 tokenId)
DsafeTransferFrom(address from, address to, uint256 tokenId)
Attempts:
2 left
💡 Hint
The function should ensure the recipient can handle ERC-721 tokens safely.
🔧 Debug
advanced
2:00remaining
What error does this ERC-721 mint function produce?
Given this mint function snippet, what error will occur when calling mint(msg.sender, 0)?
Blockchain / Solidity
mapping(uint256 => address) private _owners;

function mint(address to, uint256 tokenId) public {
    require(to != address(0), "ERC721: mint to the zero address");
    require(!_exists(tokenId), "ERC721: token already minted");
    _owners[tokenId] = to;
}

function _exists(uint256 tokenId) internal view returns (bool) {
    return _owners[tokenId] != address(0);
}
AToken ID 0 is invalid and causes a runtime error
BNo error, token minted successfully
CRevert with "ERC721: token already minted"
DRevert with "ERC721: mint to the zero address"
Attempts:
2 left
💡 Hint
Check the conditions and what _exists returns for tokenId 0 initially.
📝 Syntax
advanced
2:00remaining
Which option correctly implements the supportsInterface function for ERC-721?
The ERC-721 standard requires implementing supportsInterface(bytes4 interfaceId). Which of the following implementations correctly returns true for the ERC-721 interface ID (0x80ac58cd) and false otherwise?
A
function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
    if (interfaceId == 0x80ac58cd) {
        return true;
    } else {
        return false;
    }
}
B
function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
    return interfaceId == 0x80ac58cd;
}
C
function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
    return interfaceId != 0x80ac58cd;
}
D
function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
    return interfaceId == 0x80ac58cd || interfaceId == 0x5b5e139f;
}
Attempts:
2 left
💡 Hint
Check which option returns true only for 0x80ac58cd and false for others.
🚀 Application
expert
3:00remaining
How many tokens are owned by address 0xABC after these operations?
Given the following sequence of ERC-721 operations, how many tokens does address 0xABC own at the end? 1. Mint token 1 to 0xABC 2. Mint token 2 to 0xDEF 3. Transfer token 2 from 0xDEF to 0xABC 4. Transfer token 1 from 0xABC to 0x123 5. Burn token 2 Assume all operations succeed and the burn function removes ownership.
A0
B3
C2
D1
Attempts:
2 left
💡 Hint
Track ownership changes and burning carefully.