# Traits

Traits are a very important metadata view because they tell Flowty how to enable filtering. The Traits view itself is a wrapper around an array of traits. Each trait contains:

1. The *name* of the trait (example: "Eyes")&#x20;
2. The *value* of the trait (example: "Happy")
   * Values can be anything, but complex values are currently unsupported
   * If you want a trait to be grouped properly, limit them to primitive values such as "String", "Int", or "Bool"
   * If more than 10 values exist in the collection, a search bar will show up instead
3. The *rarity* of the trait (Optional)
   * If you specify rarity, setting its description to one of the following will color-code the trait:
     * Common
     * Uncommon
     * Default (the value if left blank)
     * Epic
     * Rare
     * Legendary

<figure><img src="/files/oz4KYZDongX2VOxpREpQ" alt=""><figcaption><p>Sample trait name and value (<a href="https://github.com/Flowtyio/avataaars">Avataaars</a>) </p></figcaption></figure>

{% tabs %}
{% tab title="Sample" %}

```
pub resource NFT: NonFungibleToken.INFT, MetadataViews.Resolver {
    // ...

    pub fun resolveView(_ view: Type): AnyStruct? {
        switch view {
            // ...
            case Type<MetadataViews.Traits>():
                // dict must be a subset of `{String: AnyStruct}`, Avataaars uses `{String: String}`
                let traitsView = MetadataViews.dictToTraits(dict: self.renderer.flattened, excludedNames: [])
                return traitsView

        }
        return nil
    }

    // ...
}
```

{% endtab %}

{% tab title="Definition" %}

```
/// View to represent a single field of metadata on an NFT.
/// This is used to get traits of individual key/value pairs along with some
/// contextualized data about the trait
///
pub struct Trait {
    // The name of the trait. Like Background, Eyes, Hair, etc.
    pub let name: String

    // The underlying value of the trait, the rest of the fields of a trait provide context to the value.
    pub let value: AnyStruct

    // displayType is used to show some context about what this name and value represent
    // for instance, you could set value to a unix timestamp, and specify displayType as "Date" to tell
    // platforms to consume this trait as a date and not a number
    pub let displayType: String?

    // Rarity can also be used directly on an attribute.
    //
    // This is optional because not all attributes need to contribute to the NFT's rarity.
    pub let rarity: Rarity?

    // truncated
}

/// Wrapper view to return all the traits on an NFT.
/// This is used to return traits as individual key/value pairs along with
/// some contextualized data about each trait.
pub struct Traits {
    pub let traits: [Trait]
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flowty.io/developer-docs/nft-metadata-standard/traits.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
