Traits

What data exists on this NFT?

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")

  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

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
    }

    // ...
}

Last updated