0
0
Blockchain / Solidityprogramming~10 mins

ERC-721 implementation in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the contract inherits from the OpenZeppelin ERC721 standard.

Blockchain / Solidity
contract MyNFT is [1] {
    constructor() ERC721("MyNFT", "MNFT") {}
}
Drag options to blanks, or click blank then click option'
AERC721
BERC20
COwnable
DIERC20
Attempts:
3 left
💡 Hint
Common Mistakes
Using ERC20 instead of ERC721
Not inheriting any contract
2fill in blank
medium

Complete the function to mint a new token to the given address.

Blockchain / Solidity
function mintNFT(address to, uint256 tokenId) public {
    _[1](to, tokenId);
}
Drag options to blanks, or click blank then click option'
Amint
BsafeMint
CtransferFrom
DsafeTransferFrom
Attempts:
3 left
💡 Hint
Common Mistakes
Using mint instead of _safeMint
Using transfer functions to mint
3fill in blank
hard

Fix the error in the function that returns the token URI.

Blockchain / Solidity
function tokenURI(uint256 tokenId) public view override returns (string memory) {
    require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
    return string(abi.encodePacked(_baseURI(), [1]));
}
Drag options to blanks, or click blank then click option'
AStrings.toString(tokenId)
BtoString(tokenId)
CtokenId
Duint2str(tokenId)
Attempts:
3 left
💡 Hint
Common Mistakes
Using tokenId directly (uint) in string concatenation
Using undefined conversion functions
4fill in blank
hard

Fill both blanks to define a mapping and a function to check token ownership.

Blockchain / Solidity
mapping(uint256 => address) private [1];

function ownerOf(uint256 tokenId) public view override returns (address) {
    address owner = [2][tokenId];
    require(owner != address(0), "ERC721: owner query for nonexistent token");
    return owner;
}
Drag options to blanks, or click blank then click option'
A_owners
Bowners
DtokenOwners
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for mapping and access
Using public instead of private mapping
5fill in blank
hard

Fill all three blanks to implement a function that safely transfers a token.

Blockchain / Solidity
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public override {
    require(_isApprovedOrOwner(msg.sender, tokenId), "ERC721: caller is not token owner nor approved");
    [1](from, to, tokenId, data);
}

function [2](address from, address to, uint256 tokenId, bytes memory data) internal {
    _transfer(from, to, tokenId);
    require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
}

function [3](address from, address to, uint256 tokenId) internal {
    // actual transfer logic here
}
Drag options to blanks, or click blank then click option'
A_safeTransfer
C_transfer
D_transferFrom
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up function names
Calling transfer instead of safeTransfer