Complete the code to declare the contract inherits from the OpenZeppelin ERC721 standard.
contract MyNFT is [1] { constructor() ERC721("MyNFT", "MNFT") {} }
The contract must inherit from ERC721 to implement the NFT standard.
Complete the function to mint a new token to the given address.
function mintNFT(address to, uint256 tokenId) public {
_[1](to, tokenId);
}_safeMint safely mints a new token and checks if the receiver can handle NFTs.
Fix the error in the function that returns the token URI.
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]));
}The Strings.toString function converts the tokenId to a string for URI concatenation.
Fill both blanks to define a mapping and a function to check token ownership.
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; }
The standard ERC721 implementation uses a private mapping named _owners to track token owners.
Fill all three blanks to implement a function that safely transfers a token.
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 }
The public function calls _safeTransfer, which calls _transfer to move the token.