Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EVMBridgedMetadata & URI to MetadataViews #203

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions contracts/MetadataViews.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,32 @@ pub contract MetadataViews {
}
}

/// A struct to represent a generic URI. May be used to represent the URI of
/// the NFT where the type of URI is not able to be determined (i.e. HTTP,
/// IPFS, etc.)
///
pub struct URI: File {
/// The base URI prefix, if any. Not needed for all URIs, but helpful
/// for some use cases For example, updating a whole NFT collection's
/// image host easily
///
pub let baseURI: String?
/// The URI string value
/// NOTE: this is set on init as a concatenation of the baseURI and the
/// value if baseURI != nil
///
access(self) let value: String

pub view fun uri(): String {
return self.value
}

init(baseURI: String?, value: String) {
self.baseURI = baseURI
self.value = baseURI != nil ? baseURI!.concat(value) : value
}
}

/// 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.
Expand Down Expand Up @@ -737,4 +763,44 @@ pub contract MetadataViews {
return Traits(traits)
}

/// This view may be used by Cadence-native projects to define their
/// contract- and token-level metadata according to EVM-compatible formats.
/// Several ERC standards (e.g. ERC20, ERC721, etc.) expose name and symbol
/// values to define assets as well as contract- & token-level metadata view
/// `tokenURI(uint256)` and `contractURI()` methods. This view enables
/// Cadence projects to define in their own contracts how they would like
/// their metadata to be defined when bridged to EVM.
///
pub struct EVMBridgedMetadata {

/// The name of the asset
///
pub let name: String

/// The symbol of the asset
///
pub let symbol: String

/// The URI of the asset - this can either be contract-level or
/// token-level URI depending on where the metadata is resolved. It
/// is recommended to reference EVM metadata standards for how to best
/// prepare your view's formatted value.
///
/// For example, while you may choose to take advantage of onchain
/// metadata, as is the case for most Cadence NFTs, you may also choose
/// to represent your asset's metadata in IPFS and assign this value as
/// an IPFSFile struct pointing to that IPFS file. Alternatively, you
/// may serialize your NFT's metadata and assign it as a JSON string
/// data URL representating the NFT's onchain metadata at the time this
/// view is resolved.
///
pub let uri: {File}

init(name: String, symbol: String, uri: {File}) {
self.name = name
self.symbol = symbol
self.uri = uri
}
}

}
Loading
Loading