NFT Traits

If you’re creating an NFT marketplace or wallet experience, displaying the traits within a collection or for a given NFT enables your users to more easily understand or explore and find the NFTs they’re looking for. Unfortunately, it can be extremely difficult to access and organize traits for a collection or specific NFT without a significant amount of manual effort parsing through metadata. Luckily, with Mnemonic, getting this useful information is as easy as a simple API call!

There are various ways you can look up traits with Mnemonic's API. Since we are looking up the traits for a specific NFT, we will use the GetNFTAllTraits method. If we wanted to get traits for all NFTs within a collection, we would use one of the methods under our Collection Service to do so.

The GetNftAllTraits method requires two parameters to run including the contract address of the collection for the NFT you're looking up, and the NFT's tokenID. If you'd like to, you can elect to limit your results, or to set an offset to start the values returned from. In this example, we'll keep it simple and just use the required parameters.

Here is what our query will look like:

curl -L 'https://ethereum-rest.api.mnemonichq.com/foundational/v1beta2/nfts/0x34d85c9cdeb23fa97cb08333b511ac86e1c4e258/1000/traits/all' \
-H 'X-API-Key: YOUR-API-KEY-HERE'

The result will look something like this:

{
    "traits": [
        {
            "name": "Category",
            "displayType": "DISPLAY_TYPE_PROPERTY",
            "valueString": "Growth"
        },
        {
            "name": "Eastern Resource",
            "displayType": "DISPLAY_TYPE_PROPERTY",
            "valueString": "Bonestone"
        },
        {
            "name": "Eastern Resource Tier",
            "displayType": "DISPLAY_TYPE_STAT",
            "valueNumeric": 3
        },
        {
            "name": "Environment",
            "displayType": "DISPLAY_TYPE_PROPERTY",
            "valueString": "Mycelium"
        },
        {
            "name": "Environment Tier",
            "displayType": "DISPLAY_TYPE_STAT",
            "valueNumeric": 3
        },
        {
            "name": "Plot",
            "displayType": "DISPLAY_TYPE_STAT",
            "valueNumeric": 1000
        },
        {
            "name": "Sediment",
            "displayType": "DISPLAY_TYPE_PROPERTY",
            "valueString": "Biogenic Swamp"
        },
        {
            "name": "Sediment Tier",
            "displayType": "DISPLAY_TYPE_STAT",
            "valueNumeric": 1
        },
        {
            "name": "Southern Resource",
            "displayType": "DISPLAY_TYPE_PROPERTY",
            "valueString": "Spikeweed"
        },
        {
            "name": "Southern Resource Tier",
            "displayType": "DISPLAY_TYPE_STAT",
            "valueNumeric": 1
        }
    ]
}

Displaying different types of NFT traits

Now that you have a list of NFT traits for an NFT, you are probably considering how you can best format and display this information in your product. Displaying NFT traits can be tricky since there are many different types and purposes of NFT traits. We designed our response structure to make this as easy as possible for you. Let's look at how this works.

You'll notice that there are several different displayType values in our response. The displayType schema value is handy for indicating deeper context around the type of trait involved and helping you see how you can most effectively visualize the value of the trait in your UI.

There are several different possible values for an NFT trait's displayType, including:

  • DISPLAY_TYPE_PROPERTY
  • DISPLAY_TYPE_LEVEL
  • DISPLAY_TYPE_STAT
  • DISPLAY_TYPE_BOOST
  • DISPLAY_TYPE_BOOST_PERCENTAGE
  • DISPLAY_TYPE_DATE

Next, you will notice that each result in our array has one value populated: valueString, valueNumeric, or valueDate. This way, it is always clear what type of trait you are working with, and what type of value the trait has so you can easily display the traits in the neatest possible way for your users.

Conclusion

Now you know how to look up a summary of NFT traits for an individual NFT on Polygon or Ethereum using Mnemonic’s Foundational NFT data API.

We love feedback here at Mnemonic! After you’ve completed this tutorial, let us know about your experience or share feedback by tagging us on Twitter @mnemonichq or reaching out directly to us at [email protected]!