Contract MetadataViews
_10pub 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
​
_10pub 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.
ResolverCollection
​
_10pub resource interface ResolverCollection {_10}
A group of view resolvers indexed by ID.
File
​
_10pub 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.
Structs & Resources​
NFTView
​
_18pub 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.
Display
​
_10pub 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.
HTTPFile
​
_10pub struct HTTPFile {_10_10 pub let url: String_10}
View to expose a file that is accessible at an HTTP (or HTTPS) URL.
IPFSFile
​
_10pub 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.
Edition
​
_10pub 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
Editions
​
_10pub struct Editions {_10_10 pub let infoList: [Edition]_10}
Wrapper view for multiple Edition views
Serial
​
_10pub 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
Royalty
​
_10pub 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.
Royalties
​
_10pub 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.
Media
​
_10pub 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.
Medias
​
_10pub struct Medias {_10_10 pub let items: [Media]_10}
Wrapper view for multiple media views
License
​
_10pub 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.
ExternalURL
​
_10pub 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.
NFTCollectionData
​
_16pub 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.
NFTCollectionDisplay
​
_14pub 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.
Rarity
​
_10pub 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
Trait
​
_10pub 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
Traits
​
_10pub 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.
Functions​
getNFTView()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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()
​
_10fun 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