Adding rich attributes to your ERC721 token
The ERC721 spec only provides a very limited metadata implementation - name
, description
and image
- but with some collections having thousands of items it's useful to be able to add more explicit details about what makes a piece unique.
Note: the following examples are not part of the ERC721 spec, however are supported by most marketplaces. You can read more about these special attributes here.
Usually you'll even be able to filter and sort by attributes, helping your fans find the rarest pieces. All of these traits can be mixed together, but be aware they may be displayed differently (or not at all) depending on the marketplace.
Attributes
Attributes are essentially 'categories' that your token has. They appear under Properties on OpenSea, and show how many other tokens have the same trait.
This is really useful, as it makes it easy to tell if a particular token is rare or not. Attributes can be added to your metadata in the following format:
{
"attributes": [
{
"trait_type": "Expression",
"value": "Happy"
},
{
"trait_type": "Eyes",
"value": "Big"
}
]
}
Numeric Traits
Numeric traits are used to show special attributes or powers your token has. OpenSea supports three different types of numeric trait:
number
- shown as a plain number (e.g 10), useful for stats like age, generation or drop numberboost_percentage
- show as a percentage increase (e.g. +20%), perfect for stat perksboost_number
- shown as a numeric increase (e.g.+20)
Numeric traits are added the same was as attributes, but with a special field indicating the type:
{
"attributes": [
{
"display_type": "boost_number",
"trait_type": "Aqua Power",
"value": 40
},
{
"display_type": "boost_percentage",
"trait_type": "Stamina Increase",
"value": 10
},
{
"display_type": "number",
"trait_type": "Generation",
"value": 2
}
]
}
Date Traits
Finally, OpenSea supports date
traits which are formatted as a date. The value should be a Unix timestamp.
{
"attributes": [
{
"display_type": "date",
"trait_type": "Birthday",
"value": 1546360800
}
]
}