Skip to main content
Version: Current

Contract MetadataViews


_10
pub contract MetadataViews {
_10
}

This contract implements the metadata standard proposed in FLIP-0636.

Ref: https://github.com/onflow/flips/blob/main/application/20210916-nft-metadata.md

Structs and resources can implement one or more metadata types, called views. Each view type represents a different kind of metadata, such as a creator biography or a JPEG image file.

Interfaces

Resolver


_10
pub resource interface Resolver {
_10
}

Provides access to a set of metadata views. A struct or resource (e.g. an NFT) can implement this interface to provide access to the views that it supports.

More...


ResolverCollection


_10
pub resource interface ResolverCollection {
_10
}

A group of view resolvers indexed by ID.

More...


File


_10
pub struct interface File {
_10
}

Generic interface that represents a file stored on or off chain. Files can be used to references images, videos and other media.

More...


Structs & Resources

NFTView


_18
pub struct NFTView {
_18
_18
pub let id: UInt64
_18
_18
pub let uuid: UInt64
_18
_18
pub let display: Display?
_18
_18
pub let externalURL: ExternalURL?
_18
_18
pub let collectionData: NFTCollectionData?
_18
_18
pub let collectionDisplay: NFTCollectionDisplay?
_18
_18
pub let royalties: Royalties?
_18
_18
pub let traits: Traits?
_18
}

NFTView wraps all Core views along id and uuid fields, and is used to give a complete picture of an NFT. Most NFTs should implement this view.

More...


Display


_10
pub struct Display {
_10
_10
pub let name: String
_10
_10
pub let description: String
_10
_10
pub let thumbnail: AnyStruct{File}
_10
}

Display is a basic view that includes the name, description and thumbnail for an object. Most objects should implement this view.

More...


HTTPFile


_10
pub struct HTTPFile {
_10
_10
pub let url: String
_10
}

View to expose a file that is accessible at an HTTP (or HTTPS) URL.

More...


IPFSFile


_10
pub struct IPFSFile {
_10
_10
pub let cid: String
_10
_10
pub let path: String?
_10
}

View to expose a file stored on IPFS. IPFS images are referenced by their content identifier (CID) rather than a direct URI. A client application can use this CID to find and load the image via an IPFS gateway.

More...


Edition


_10
pub struct Edition {
_10
_10
pub let name: String?
_10
_10
pub let number: UInt64
_10
_10
pub let max: UInt64?
_10
}

Optional view for collections that issue multiple objects with the same or similar metadata, for example an X of 100 set. This information is useful for wallets and marketplaces. An NFT might be part of multiple editions, which is why the edition information is returned as an arbitrary sized array

More...


Editions


_10
pub struct Editions {
_10
_10
pub let infoList: [Edition]
_10
}

Wrapper view for multiple Edition views

More...


Serial


_10
pub struct Serial {
_10
_10
pub let number: UInt64
_10
}

View representing a project-defined serial number for a specific NFT Projects have different definitions for what a serial number should be Some may use the NFTs regular ID and some may use a different classification system. The serial number is expected to be unique among other NFTs within that project

More...


Royalty


_10
pub struct Royalty {
_10
_10
pub let receiver: Capability<&AnyResource{FungibleToken.Receiver}>
_10
_10
pub let cut: UFix64
_10
_10
pub let description: String
_10
}

View that defines the composable royalty standard that gives marketplaces a unified interface to support NFT royalties.

More...


Royalties


_10
pub struct Royalties {
_10
_10
priv let cutInfos: [Royalty]
_10
}

Wrapper view for multiple Royalty views. Marketplaces can query this Royalties struct from NFTs and are expected to pay royalties based on these specifications.

More...


Media


_10
pub struct Media {
_10
_10
pub let file: AnyStruct{File}
_10
_10
pub let mediaType: String
_10
}

View to represent, a file with an correspoiding mediaType.

More...


Medias


_10
pub struct Medias {
_10
_10
pub let items: [Media]
_10
}

Wrapper view for multiple media views

More...


License


_10
pub struct License {
_10
_10
pub let spdxIdentifier: String
_10
}

View to represent a license according to https://spdx.org/licenses/ This view can be used if the content of an NFT is licensed.

More...


ExternalURL


_10
pub struct ExternalURL {
_10
_10
pub let url: String
_10
}

View to expose a URL to this item on an external site. This can be used by applications like .find and Blocto to direct users to the original link for an NFT.

More...


NFTCollectionData


_16
pub struct NFTCollectionData {
_16
_16
pub let storagePath: StoragePath
_16
_16
pub let publicPath: PublicPath
_16
_16
pub let providerPath: PrivatePath
_16
_16
pub let publicCollection: Type
_16
_16
pub let publicLinkedType: Type
_16
_16
pub let providerLinkedType: Type
_16
_16
pub let createEmptyCollection: ((): @NonFungibleToken.Collection)
_16
}

View to expose the information needed store and retrieve an NFT. This can be used by applications to setup a NFT collection with proper storage and public capabilities.

More...


NFTCollectionDisplay


_14
pub struct NFTCollectionDisplay {
_14
_14
pub let name: String
_14
_14
pub let description: String
_14
_14
pub let externalURL: ExternalURL
_14
_14
pub let squareImage: Media
_14
_14
pub let bannerImage: Media
_14
_14
pub let socials: {String: ExternalURL}
_14
}

View to expose the information needed to showcase this NFT's collection. This can be used by applications to give an overview and graphics of the NFT collection this NFT belongs to.

More...


Rarity


_10
pub struct Rarity {
_10
_10
pub let score: UFix64?
_10
_10
pub let max: UFix64?
_10
_10
pub let description: String?
_10
}

View to expose rarity information for a single rarity Note that a rarity needs to have either score or description but it can have both

More...


Trait


_10
pub struct Trait {
_10
_10
pub let name: String
_10
_10
pub let value: AnyStruct
_10
_10
pub let displayType: String?
_10
_10
pub let rarity: Rarity?
_10
}

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

More...


Traits


_10
pub struct Traits {
_10
_10
pub let traits: [Trait]
_10
}

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.

More...


Functions

getNFTView()


_10
fun getNFTView(id: UInt64, viewResolver: &{Resolver}): NFTView

Helper to get an NFT view

Parameters:

  • id : The NFT id
  • viewResolver : A reference to the resolver resource

Returns: A NFTView struct


getDisplay()


_10
fun getDisplay(_: &{Resolver}): Display?

Helper to get Display in a typesafe way

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: An optional Display struct


getEditions()


_10
fun getEditions(_: &{Resolver}): Editions?

Helper to get Editions in a typesafe way

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: An optional Editions struct


getSerial()


_10
fun getSerial(_: &{Resolver}): Serial?

Helper to get Serial in a typesafe way

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: An optional Serial struct


getRoyalties()


_10
fun getRoyalties(_: &{Resolver}): Royalties?

Helper to get Royalties in a typesafe way

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: A optional Royalties struct


getRoyaltyReceiverPublicPath()


_10
fun getRoyaltyReceiverPublicPath(): PublicPath

Get the path that should be used for receiving royalties This is a path that will eventually be used for a generic switchboard receiver, hence the name but will only be used for royalties for now.

Returns: The PublicPath for the generic FT receiver


getMedias()


_10
fun getMedias(_: &{Resolver}): Medias?

Helper to get Medias in a typesafe way

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: A optional Medias struct


getLicense()


_10
fun getLicense(_: &{Resolver}): License?

Helper to get License in a typesafe way

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: A optional License struct


getExternalURL()


_10
fun getExternalURL(_: &{Resolver}): ExternalURL?

Helper to get ExternalURL in a typesafe way

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: A optional ExternalURL struct


getNFTCollectionData()


_10
fun getNFTCollectionData(_: &{Resolver}): NFTCollectionData?

Helper to get NFTCollectionData in a way that will return an typed Optional

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: A optional NFTCollectionData struct


getNFTCollectionDisplay()


_10
fun getNFTCollectionDisplay(_: &{Resolver}): NFTCollectionDisplay?

Helper to get NFTCollectionDisplay in a way that will return a typed Optional

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: A optional NFTCollection struct


getRarity()


_10
fun getRarity(_: &{Resolver}): Rarity?

Helper to get Rarity view in a typesafe way

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: A optional Rarity struct


getTraits()


_10
fun getTraits(_: &{Resolver}): Traits?

Helper to get Traits view in a typesafe way

Parameters:

  • viewResolver : A reference to the resolver resource

Returns: A optional Traits struct


dictToTraits()


_10
fun dictToTraits(dict: {String: AnyStruct}, excludedNames: [String]?): Traits

Helper function to easily convert a dictionary to traits. For NFT collections that do not need either of the optional values of a Trait, this method should suffice to give them an array of valid traits.

keys that are not wanted to become Traits

Parameters:

  • dict : The dictionary to be converted to Traits
  • excludedNames : An optional String array specifying the dict

Returns: The generated Traits view