Challenge - 5 Problems
Token Metadata Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Solidity function fetching token URI?
Consider this Solidity function that returns a token URI based on token ID. What will be the output when calling
tokenURI(42)?Blockchain / Solidity
function tokenURI(uint256 tokenId) public view returns (string memory) {
string memory baseURI = "https://example.com/metadata/";
return string(abi.encodePacked(baseURI, Strings.toString(tokenId), ".json"));
}Attempts:
2 left
💡 Hint
Look at how the base URI and token ID are concatenated with the file extension.
✗ Incorrect
The function concatenates the base URI, the string form of the token ID, and the '.json' extension. For tokenId 42, it returns 'https://example.com/metadata/42.json'.
🧠 Conceptual
intermediate1:30remaining
Which standard defines the metadata URI for ERC-721 tokens?
In Ethereum, which standard specifies how token metadata URI should be exposed for NFTs?
Attempts:
2 left
💡 Hint
This standard is the original NFT standard.
✗ Incorrect
ERC-721 is the standard for non-fungible tokens and defines the
tokenURI function to provide metadata URI.🔧 Debug
advanced2:30remaining
Why does this tokenURI function revert with 'URI query for nonexistent token' error?
Given this Solidity snippet, why does calling
tokenURI(10) revert?
function tokenURI(uint256 tokenId) public view returns (string memory) {
require(_exists(tokenId), "URI query for nonexistent token");
return _tokenURIs[tokenId];
}Blockchain / Solidity
mapping(uint256 => string) private _tokenURIs; function _exists(uint256 tokenId) internal view returns (bool) { return _owners[tokenId] != address(0); } mapping(uint256 => address) private _owners;
Attempts:
2 left
💡 Hint
Check what _exists function checks before returning URI.
✗ Incorrect
The require statement checks if the token exists by verifying if it has an owner. If token 10 has no owner, _exists returns false and the require fails, reverting the call.
📝 Syntax
advanced2:00remaining
Which option correctly implements a tokenURI function with base URI and token ID?
Select the correct Solidity function that returns the token URI by concatenating a base URI and token ID.
Attempts:
2 left
💡 Hint
Remember tokenId is a number and needs conversion to string before concatenation.
✗ Incorrect
Option D correctly converts tokenId to string using Strings.toString and concatenates with baseURI using abi.encodePacked. Other options either try to concatenate string with uint directly or use invalid methods.
🚀 Application
expert3:00remaining
How many metadata JSON files are needed for an ERC-1155 contract with 3 token types?
An ERC-1155 contract manages 3 different token types with IDs 1, 2, and 3. Each token type has unique metadata. How many separate JSON metadata files should be hosted to fully support tokenURI calls?
Attempts:
2 left
💡 Hint
Each token type in ERC-1155 can have its own metadata URI.
✗ Incorrect
ERC-1155 tokens can have individual metadata URIs per token ID. For 3 token types, 3 separate JSON metadata files are needed, one for each token ID.