Generate NFT metadata and ensure uniqueness
CoinbaseSoftware Engineer · OnsiteLast updated
This question evaluates understanding of combinatorics, deterministic pseudo-random generation, and efficient enumeration for producing unique NFT metadata, measuring competency in algorithm design, state-space management, and handling large-scale outputs.
You are implementing an NFT metadata generator. Each NFT is defined by selecting exactly one trait value from each trait category. You must generate a requested number of NFTs, ensure they are unique (no repeated trait combinations), and output JSON metadata.
Input
A single JSON object with:
collectionName(string)traits: an array of trait categories. Each category is:name(string)values(array of strings, non-empty)n(integer): number of NFTs to generateseed(integer): seed for deterministic pseudo-random generation
Example:
{
"collectionName": "MyCollection",
"traits": [
{"name": "Background", "values": ["Blue", "Red"]},
{"name": "Eyes", "values": ["Normal", "Laser"]}
],
"n": 3,
"seed": 42
}
Required behavior
- Each generated NFT must have exactly one value for each trait category.
- Two NFTs are considered the same if they have the same value for every trait category.
- Use
seedto make generation deterministic:
- Using the same input must produce the same outputs in the same order.
- If
nexceeds the number of possible unique combinations, outputERROR.
Output
Output a JSON array of length n. Each element is an object:
name:"<collectionName> #<index>"whereindexstarts at 1attributes: array of{ "trait_type": <categoryName>, "value": <selectedValue> }
Example output element:
{
"name": "MyCollection #1",
"attributes": [
{"trait_type": "Background", "value": "Red"},
{"trait_type": "Eyes", "value": "Laser"}
]
}
Constraints
- Up to 10 trait categories.
- Each category has up to 200 values.
ncan be up to 100,000.
Notes
You must define your own approach for generating unique combinations efficiently (not by repeatedly sampling and retrying until unique).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.