Token metadata is information that describes a token's properties, such as its name, symbol, description, image, and other attributes that help users and applications understand the token.
Click to reveal answer
beginner
What does URI stand for and what is its role in token metadata?
URI stands for Uniform Resource Identifier. In token metadata, it points to the location where the token's metadata JSON file is stored, often on IPFS or a web server.
Click to reveal answer
intermediate
Why is storing token metadata off-chain common practice?
Because storing large amounts of data on the blockchain is expensive and inefficient, token metadata is usually stored off-chain (like on IPFS or centralized servers) and linked via a URI.
Click to reveal answer
intermediate
What is a typical structure of a token metadata JSON file?
A typical token metadata JSON includes fields like 'name', 'description', 'image' (URL or IPFS hash), and sometimes 'attributes' or 'properties' describing traits of the token.
Click to reveal answer
intermediate
How does a smart contract use the token URI?
The smart contract provides a function (like tokenURI in ERC-721) that returns the URI pointing to the token's metadata, allowing wallets and marketplaces to fetch and display token details.
Click to reveal answer
What does the token URI usually point to?
AThe token owner's wallet address
BThe token's smart contract code
CA JSON file containing token metadata
DThe blockchain network address
✗ Incorrect
The token URI points to a JSON file that holds the token's metadata like name, image, and description.
Why is token metadata often stored off-chain?
ABecause blockchain storage is costly and limited
BBecause metadata is not important
CBecause smart contracts cannot access metadata
DBecause off-chain data is more secure
✗ Incorrect
Storing metadata off-chain saves blockchain space and reduces costs.
Which of these is NOT typically part of token metadata JSON?
ADescription
BToken name
CImage URL
DToken owner's private key
✗ Incorrect
Private keys are secret and never included in token metadata.
What standard function returns the token URI in an ERC-721 contract?
AownerOf
BtokenURI
CgetMetadata
DtransferFrom
✗ Incorrect
The tokenURI function returns the URI pointing to the token's metadata.
Which protocol is commonly used to store token metadata off-chain?
AIPFS
BHTTP only
CFTP
DSMTP
✗ Incorrect
IPFS is a decentralized storage protocol often used for token metadata.
Explain what token metadata is and why it is important in blockchain tokens.
Think about how metadata helps describe a token beyond just its ID.
You got /3 concepts.
Describe how a token URI works and how it connects a smart contract to token metadata.
Consider how the smart contract tells apps where to find token details.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of token metadata in blockchain tokens?
easy
A. To mine new tokens automatically
B. To describe the token and link to its details
C. To execute smart contract functions
D. To store the token's private key
Solution
Step 1: Understand token metadata role
Token metadata provides descriptive information about the token, such as its name, description, and image link.
Step 2: Differentiate from other blockchain functions
Metadata is not about private keys, mining, or executing contracts but about describing the token for users and apps.
Final Answer:
To describe the token and link to its details -> Option B
Quick Check:
Token metadata = description and details link [OK]
Hint: Metadata describes tokens, not keys or mining [OK]
Common Mistakes:
Confusing metadata with private keys
Thinking metadata controls token creation
Mixing metadata with smart contract code
2. Which of the following is the correct way to specify a token URI in a smart contract?
easy
A. bool tokenURI = true;
B. int tokenURI = 12345;
C. string public tokenURI = "https://example.com/token/1.json";
D. address tokenURI = 0x123;
Solution
Step 1: Identify the data type for URI
A URI is a web address, so it should be stored as a string in the contract.
Step 2: Check the options for correct syntax
string public tokenURI = "https://example.com/token/1.json"; uses a string with a valid URL format, while others use wrong types like int, bool, or address.
Final Answer:
string public tokenURI = "https://example.com/token/1.json"; -> Option C
Quick Check:
URI is a string URL [OK]
Hint: URIs are strings, not numbers or booleans [OK]
Common Mistakes:
Using int or bool for URI
Confusing address type with URI
Missing quotes around the URI string
3. Given the following Solidity snippet, what will tokenURI(1) return if _tokenURIs[1] is set to "https://example.com/metadata/1.json"?
mapping(uint256 => string) private _tokenURIs;
function tokenURI(uint256 tokenId) public view returns (string memory) {
return _tokenURIs[tokenId];
}
medium
A. An error because tokenURI is private
B. tokenId
C. Empty string
D. "https://example.com/metadata/1.json"
Solution
Step 1: Understand the mapping and function
The mapping stores strings for each tokenId. The function returns the string stored for the given tokenId.
Step 2: Check the value for tokenId 1
Since _tokenURIs[1] is set to "https://example.com/metadata/1.json", calling tokenURI(1) returns that string.
Final Answer:
"https://example.com/metadata/1.json" -> Option D
Quick Check:
Mapping lookup returns stored URI string [OK]
Hint: Mapping returns stored URI for tokenId [OK]
Common Mistakes:
Thinking tokenURI is private and inaccessible
Confusing tokenId with URI string
Assuming function returns tokenId instead of URI
4. Identify the error in this Solidity function that tries to set a token URI:
mapping(uint256 => string) private _tokenURIs;
function setTokenURI(uint256 tokenId, string memory uri) public {
_tokenURIs[tokenId] = uri;
}
medium
A. The function lacks access control and allows anyone to set URIs
B. The mapping type is incorrect for storing strings
C. The function should return a string
D. The parameter uri should be declared as calldata
Solution
Step 1: Review function purpose and security
The function sets a URI for a tokenId but has no restriction on who can call it.
Step 2: Identify missing access control
Without access control (like onlyOwner), anyone can change token URIs, which is a security risk.
Final Answer:
The function lacks access control and allows anyone to set URIs -> Option A
Quick Check:
Missing access control = security risk [OK]
Hint: Always add access control to setter functions [OK]
Common Mistakes:
Thinking mapping type is wrong for strings
Expecting setter functions to return values
Ignoring security risks of public setters
5. You want to create a function that returns a JSON metadata URI for a token, but if the token has no specific URI set, it should return a default URI. Which Solidity code snippet correctly implements this logic?
mapping(uint256 => string) private _tokenURIs;
string private _defaultURI = "https://example.com/default.json";
function tokenURI(uint256 tokenId) public view returns (string memory) {
// Fill in the blank
}
hard
A. return bytes(_tokenURIs[tokenId]).length > 0 ? _tokenURIs[tokenId] : _defaultURI;
B. if (_tokenURIs[tokenId] == null) { return _defaultURI; } else { return _tokenURIs[tokenId]; }
C. return _tokenURIs[tokenId] || _defaultURI;
D. return _tokenURIs[tokenId] == "" ? _tokenURIs[tokenId] : _defaultURI;
Solution
Step 1: Check how to test if string is empty in Solidity
Solidity strings can't be compared to null or use || operator; use bytes length to check emptiness.
Step 2: Verify correct conditional expression
return bytes(_tokenURIs[tokenId]).length > 0 ? _tokenURIs[tokenId] : _defaultURI; uses bytes(_tokenURIs[tokenId]).length > 0 to check if URI exists, else returns default URI.