Free NFT Development Marketplace Integration Questions and Answers 1 — Questions and Answers
Question 1: A user wants to list a single, specific NFT for sale on a decentralized marketplace. To grant the marketplace the most precise and secure permission to transfer only that specific NFT upon a successful sale, which function must the user call on the NFT contract?
- setApprovalForAll(marketplaceAddress, true)
- approve(marketplaceAddress, tokenId) (Correct answer)
- transferFrom(myAddress, marketplaceAddress, tokenId)
- safeTransferFrom(myAddress, marketplaceAddress, tokenId)
Correct answer: approve(marketplaceAddress, tokenId)
The `approve(address to, uint256 tokenId)` function grants an external address permission to transfer a single, specific token. This follows the principle of least privilege, as it's safer than `setApprovalForAll`, which would grant permission for all NFTs in the collection. The `transferFrom` functions would immediately transfer the token, which is not how listings work.
Question 2: A development team wants to programmatically receive a percentage of the sale price each time their NFTs are resold on compliant secondary marketplaces. Which EIP provides a standardized interface for contracts to signal and retrieve this royalty information?
- EIP-721
- EIP-1155
- EIP-165
- EIP-2981 (Correct answer)
Correct answer: EIP-2981
EIP-2981 is the NFT Royalty Standard. It specifies a `royaltyInfo(uint256 _tokenId, uint256 _salePrice)` function that marketplaces can call to determine the correct royalty recipient and amount for a given sale, enabling standardized, on-chain royalty payments.
Question 3: After deploying a new ERC-721 contract, a developer notices that marketplaces are not displaying the collection's overall name, description, or logo, although individual NFTs and their traits appear correctly. Which of the following is the most likely missing feature in the contract?
- A `tokenURI` function returning invalid JSON.
- An implementation of the EIP-2981 royalty standard.
- A `contractURI()` function that points to collection-level metadata. (Correct answer)
- The ERC721Enumerable extension.
Correct answer: A `contractURI()` function that points to collection-level metadata.
Marketplaces like OpenSea use the `contractURI()` function to pull collection-level metadata, including the name, description, and image for the collection page. While a broken `tokenURI` would affect individual NFTs, the problem described is with the collection as a whole.
Question 4: An NFT marketplace enables gas-less listings by having users sign an off-chain message that details the sale terms (e.g., NFT, price, deadline). A buyer can then submit this signed message to the marketplace's smart contract to execute the trade. What is this common integration pattern called?
- Off-chain order book with on-chain settlement (Correct answer)
- On-chain lazy minting
- State channel negotiation
- Atomic swap delegation
Correct answer: Off-chain order book with on-chain settlement
This pattern describes an off-chain order book. Sale orders are created and stored off-chain as signed messages (gas-less), and the final settlement (the actual transfer of NFT and payment) occurs on-chain when a buyer submits the valid, signed order to the contract.
Question 5: For a marketplace to programmatically discover if an NFT contract supports optional features like EIP-2981 (Royalties) or ERC721Enumerable, which standard EIP-165 function must the contract implement?
- hasFeature(bytes4 featureId)
- getInterface(bytes4 interfaceId)
- supportsInterface(bytes4 interfaceId) (Correct answer)
- isStandard(bytes4 standardId)
Correct answer: supportsInterface(bytes4 interfaceId)
EIP-165 specifies the `supportsInterface(bytes4 interfaceId)` function. This function allows external contracts and platforms to check if a contract implements a specific set of functions, defined as an interface. Marketplaces use this to gracefully handle different NFT features.
Question 6: Which of the following represents the most significant security risk to a user who calls `setApprovalForAll(marketplaceAddress, true)` on their NFT contract?
- The gas cost for the transaction will be unpredictably high.
- The marketplace will be able to mint new tokens on the user's behalf.
- The user will no longer be able to burn their own NFTs.
- A vulnerability in the marketplace contract could allow an attacker to drain all of the user's approved NFTs from that collection. (Correct answer)
Correct answer: A vulnerability in the marketplace contract could allow an attacker to drain all of the user's approved NFTs from that collection.
`setApprovalForAll` grants the specified address (the marketplace) ongoing permission to transfer ALL NFTs the user owns in that collection. If the marketplace's contract has a reentrancy bug or other vulnerability, an attacker could exploit it to call `transferFrom` repeatedly, stealing every approved NFT from the user's wallet.
A user wants to list a single, specific NFT for sale on a decentralized marketplace.
To grant the marketplace the most precise and secure permission to transfer only that specific NFT upon a successful sale, which function must the user call on the NFT contract?