Bird
Raised Fist0
Blockchain / Solidityprogramming~5 mins

ERC-721 implementation in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is ERC-721 in blockchain?
ERC-721 is a standard for creating Non-Fungible Tokens (NFTs) on the Ethereum blockchain. Each token is unique and cannot be replaced by another.
Click to reveal answer
beginner
What function in ERC-721 returns the owner of a specific token?
The function ownerOf(tokenId) returns the address of the owner of the token with the given tokenId.
Click to reveal answer
intermediate
Why does ERC-721 require a transferFrom function?
The transferFrom function allows the owner or an approved address to transfer ownership of a token to another address, enabling token trading and movement.
Click to reveal answer
intermediate
What is the purpose of the approve function in ERC-721?
The approve function lets the token owner authorize another address to transfer a specific token on their behalf.
Click to reveal answer
intermediate
Name two events defined in the ERC-721 standard and their purpose.
1. Transfer: Emitted when ownership of a token changes.
2. Approval: Emitted when a token owner approves another address to manage a token.
Click to reveal answer
Which function in ERC-721 returns the total number of tokens owned by an address?
AownerOf
BbalanceOf
CtotalSupply
DtokenURI
What does the tokenURI function provide in an ERC-721 contract?
AThe owner address of a token
BThe total number of tokens
CThe metadata URL for a token
DThe approval status of a token
Which event is emitted when a token is transferred in ERC-721?
ATransfer
BTokenMoved
COwnershipChanged
DApproval
What is the main difference between ERC-20 and ERC-721 tokens?
AERC-20 tokens are only for Ethereum, ERC-721 tokens are for Bitcoin
BERC-20 tokens are unique, ERC-721 tokens are fungible
CERC-20 tokens cannot be transferred, ERC-721 tokens can
DERC-20 tokens are fungible, ERC-721 tokens are unique
Which function allows an approved address to transfer a token on behalf of the owner?
AtransferFrom
BsafeTransferFrom
Capprove
DsetApprovalForAll
Explain the key functions and events that an ERC-721 contract must implement.
Think about how tokens are owned, transferred, and approved.
You got /7 concepts.
    Describe how ERC-721 tokens differ from ERC-20 tokens and why this matters.
    Consider what makes each token type special and their typical uses.
    You got /4 concepts.

      Practice

      (1/5)
      1.

      What is the main purpose of the ERC-721 standard in blockchain?

      easy
      A. To create fungible tokens like cryptocurrencies
      B. To manage smart contract ownership
      C. To create unique, non-fungible tokens (NFTs)
      D. To enable fast transaction processing

      Solution

      1. Step 1: Understand ERC-721 token type

        ERC-721 defines a standard for unique tokens, unlike fungible tokens which are identical.
      2. Step 2: Identify the purpose of ERC-721

        It is used to create NFTs, which are unique digital assets on the blockchain.
      3. Final Answer:

        To create unique, non-fungible tokens (NFTs) -> Option C
      4. Quick Check:

        ERC-721 = Unique NFTs [OK]
      Hint: ERC-721 is for unique tokens, not identical ones [OK]
      Common Mistakes:
      • Confusing ERC-721 with ERC-20 fungible tokens
      • Thinking ERC-721 manages contract ownership
      • Assuming ERC-721 speeds up transactions
      2.

      Which of the following is the correct way to inherit OpenZeppelin's ERC721 contract in Solidity?

      contract MyNFT is ? {}
      easy
      A. SafeMath
      B. ERC721
      C. Ownable
      D. ERC20

      Solution

      1. Step 1: Identify the correct base contract for NFTs

        ERC721 is the OpenZeppelin contract for NFTs, ERC20 is for fungible tokens.
      2. Step 2: Confirm inheritance syntax

        Using is ERC721 correctly inherits the NFT functionality.
      3. Final Answer:

        ERC721 -> Option B
      4. Quick Check:

        Inherit ERC721 for NFTs [OK]
      Hint: Use ERC721 to inherit NFT features [OK]
      Common Mistakes:
      • Using ERC20 instead of ERC721
      • Confusing Ownable with ERC721
      • Trying to inherit SafeMath for NFTs
      3.

      What will be the output of the following Solidity function when called?

      function mintToken(address to, uint256 tokenId) public {
          _mint(to, tokenId);
      }
      
      // Assume _mint works as expected and tokenId = 1, to = 0x123...

      What happens after calling mintToken(0x123..., 1)?

      medium
      A. A new NFT with tokenId 1 is assigned to address 0x123...
      B. The tokenId 1 is burned from address 0x123...
      C. The function throws a syntax error
      D. The tokenId 1 is transferred from 0x123... to the caller

      Solution

      1. Step 1: Understand the _mint function

        _mint creates a new token with the given tokenId and assigns it to the 'to' address.
      2. Step 2: Analyze the function call

        Calling mintToken with address 0x123... and tokenId 1 creates that NFT for 0x123....
      3. Final Answer:

        A new NFT with tokenId 1 is assigned to address 0x123... -> Option A
      4. Quick Check:

        mintToken creates NFT for 'to' address [OK]
      Hint: _mint assigns new token to given address [OK]
      Common Mistakes:
      • Thinking _mint burns tokens
      • Assuming _mint transfers tokens
      • Expecting syntax errors from correct code
      4.

      Identify the error in this Solidity snippet for minting an ERC-721 token:

      function mint(address to, uint256 tokenId) public {
          _mint(tokenId, to);
      }

      medium
      A. Function must be named mintToken, not mint
      B. _mint cannot be called inside a public function
      C. tokenId must be a string, not uint256
      D. _mint parameters are reversed; should be (to, tokenId)

      Solution

      1. Step 1: Check _mint function parameter order

        OpenZeppelin's _mint expects (address to, uint256 tokenId).
      2. Step 2: Compare with given code

        The code uses _mint(tokenId, to), reversing the parameters.
      3. Final Answer:

        _mint parameters are reversed; should be (to, tokenId) -> Option D
      4. Quick Check:

        _mint(to, tokenId) correct order [OK]
      Hint: _mint needs (address, tokenId) order [OK]
      Common Mistakes:
      • Swapping parameters of _mint
      • Thinking _mint can't be public
      • Confusing tokenId type
      5.

      You want to create an ERC-721 contract that only allows the contract owner to mint new tokens. Which of these Solidity code snippets correctly enforces this?

      contract MyNFT is ERC721, Ownable {
          function mint(address to, uint256 tokenId) public {
              ?
              _mint(to, tokenId);
          }
      }
      hard
      A. require(msg.sender == owner(), "Not owner");
      B. require(to == owner(), "Not owner");
      C. require(tokenId > 0, "Invalid tokenId");
      D. require(msg.sender != owner(), "Owner cannot mint");

      Solution

      1. Step 1: Understand ownership check

        Only the contract owner should mint, so check if msg.sender equals owner().
      2. Step 2: Analyze each require statement

        require(msg.sender == owner(), "Not owner"); correctly checks sender is owner; others check wrong conditions.
      3. Final Answer:

        require(msg.sender == owner(), "Not owner"); -> Option A
      4. Quick Check:

        Owner check uses msg.sender == owner() [OK]
      Hint: Check msg.sender equals owner() before minting [OK]
      Common Mistakes:
      • Checking 'to' address instead of sender
      • Allowing anyone to mint without checks
      • Using wrong require conditions
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard