Contract MetadataViews
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
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.
ResolverCollection
A group of view resolvers indexed by ID.
File
Generic interface that represents a file stored on or off chain. Files can be used to references images, videos and other media.
Structs & Resources
NFTView
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.
Display
Display is a basic view that includes the name, description and thumbnail for an object. Most objects should implement this view.
HTTPFile
View to expose a file that is accessible at an HTTP (or HTTPS) URL.
IPFSFile
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.
Edition
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
Editions
Wrapper view for multiple Edition views
Serial
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
Royalty
View that defines the composable royalty standard that gives marketplaces a unified interface to support NFT royalties.
Royalties
Wrapper view for multiple Royalty views.
Marketplaces can query this Royalties
struct from NFTs
and are expected to pay royalties based on these specifications.
Media
View to represent, a file with an correspoiding mediaType.
Medias
Wrapper view for multiple media views
License
View to represent a license according to https://spdx.org/licenses/ This view can be used if the content of an NFT is licensed.
ExternalURL
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.
NFTCollectionData
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.
NFTCollectionDisplay
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.
Rarity
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
Trait
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
Traits
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.
Functions
getNFTView()
Helper to get an NFT view
Parameters:
- id : The NFT id
- viewResolver : A reference to the resolver resource
Returns: A NFTView struct
getDisplay()
Helper to get Display in a typesafe way
Parameters:
- viewResolver : A reference to the resolver resource
Returns: An optional Display struct
getEditions()
Helper to get Editions in a typesafe way
Parameters:
- viewResolver : A reference to the resolver resource
Returns: An optional Editions struct
getSerial()
Helper to get Serial in a typesafe way
Parameters:
- viewResolver : A reference to the resolver resource
Returns: An optional Serial struct
getRoyalties()
Helper to get Royalties in a typesafe way
Parameters:
- viewResolver : A reference to the resolver resource
Returns: A optional Royalties struct
getRoyaltyReceiverPublicPath()
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()
Helper to get Medias in a typesafe way
Parameters:
- viewResolver : A reference to the resolver resource
Returns: A optional Medias struct
getLicense()
Helper to get License in a typesafe way
Parameters:
- viewResolver : A reference to the resolver resource
Returns: A optional License struct
getExternalURL()
Helper to get ExternalURL in a typesafe way
Parameters:
- viewResolver : A reference to the resolver resource
Returns: A optional ExternalURL struct
getNFTCollectionData()
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()
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()
Helper to get Rarity view in a typesafe way
Parameters:
- viewResolver : A reference to the resolver resource
Returns: A optional Rarity struct
getTraits()
Helper to get Traits view in a typesafe way
Parameters:
- viewResolver : A reference to the resolver resource
Returns: A optional Traits struct
dictToTraits()
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