DeploySEALED
╳╲╲◆?╱#░□●%╳▫▪^&▫▓~^░╱^*%~%$□%*○▒●^◆~&■□@╲*◆▓@●╲▓░$~^█○▫█╱◆*▫?^□
Transaction ID
Execution Fee
0.00000189 FLOWTransaction Summary
DeployContract deployment
Contract deployment
Script Arguments
0nameString
Utils
1codeString
import NonFungibleToken from 0x1d7e57aa55817448
import ViewResolver from 0x1d7e57aa55817448
import MetadataViews from 0x1d7e57aa55817448
import StringUtils from 0xa340dc0a4ec828ab
import AddressUtils from 0xa340dc0a4ec828ab
import NFTCatalog from 0x49a7cda3a1eecc29
pub contract Utils {
pub fun borrowViewResolver(_ t: Type): &ViewResolver? {
let segments = StringUtils.split(t.identifier, ".")
let addr = AddressUtils.parseAddress(segments[1]) ?? panic("borrowViewResolver: unable to parse address")
let contractName = segments[2]
return getAccount(addr).contracts.borrow<&ViewResolver>(name: contractName)
}
pub fun firstCatalogEntry(_ t: Type): NFTCatalog.NFTCatalogMetadata? {
if let catalogEntries = NFTCatalog.getCollectionsForType(nftTypeIdentifier: t.identifier) {
for k in catalogEntries.keys {
if catalogEntries[k] == true {
return NFTCatalog.getCatalogEntry(collectionIdentifier: k)!
}
}
}
return nil
}
pub fun resolveCollectionMetadata(_ t: Type): CollectionMetadata? {
// if this type is in the nft catalog, we can just use its data.
if let catalogEntry = self.firstCatalogEntry(t) {
return CollectionMetadata(catalogEntry, nil, nil)
}
if let vr = self.borrowViewResolver(t) {
let display = vr.resolveView(Type<MetadataViews.NFTCollectionDisplay>()) as! MetadataViews.NFTCollectionDisplay?
let data = vr.resolveView(Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData?
return CollectionMetadata(nil, display, data)
}
return nil
}
pub fun resolveContractNftTypes(addr: Address, name: String): [String] {
let types: [String] = []
let acct = getAccount(addr)
let c = acct.contracts.get(name: name) ?? panic("contract not found")
let pts = c.publicTypes()
let nftType = Type<@NonFungibleToken.NFT>()
for t in pts {
if t.isSubtype(of: nftType) {
types.append(t.identifier)
}
}
return types
}
pub fun resolveNftMetadata(acct: AuthAccount, storagePath: StoragePath, id: UInt64): NftMetadata? {
let c = acct.borrow<&{NonFungibleToken.CollectionPublic}>(from: storagePath)
?? panic("no collection found at storage path")
let nft = c!.borrowNFT(id: id)
return NftMetadata(nft)
}
pub struct NftMetadata {
pub let id: UInt64
pub let uuid: UInt64
pub let type: String
pub let owner: Address?
pub var serial: UInt64
pub var displayName: String
pub var displayThumbnail: String?
pub var externalUrl: String?
pub var traits: [MetadataViews.Trait]
pub var editions: [MetadataViews.Edition]
init(_ nft: &NonFungibleToken.NFT) {
self.id = nft.id
self.uuid = nft.uuid
self.type = nft.getType().identifier
self.owner = nft.owner?.address
self.serial = self.id
let segments = StringUtils.split(self.type, ".")
self.displayName = segments[2].concat(" #").concat(self.serial.toString())
self.displayThumbnail = nil
self.externalUrl = nil
self.editions = []
self.traits = []
if let s = nft.resolveView(Type<MetadataViews.Serial>()) as! MetadataViews.Serial? {
self.serial = s.number
}
if let e = nft.resolveView(Type<MetadataViews.ExternalURL>()) as! MetadataViews.ExternalURL? {
self.externalUrl = e.url
}
if let display = nft.resolveView(Type<MetadataViews.Display>()) as! MetadataViews.Display? {
self.displayName = display.name
self.displayThumbnail = display.thumbnail.uri()
}
if let traits = nft.resolveView(Type<MetadataViews.Traits>()) as! MetadataViews.Traits? {
self.traits = traits.traits
}
if let editions = nft.resolveView(Type<MetadataViews.Editions>()) as! MetadataViews.Editions? {
self.editions = editions.infoList
}
}
}
pub struct CollectionMetadata {
pub var inCatalog: Bool
pub var display: CollectionDisplay?
pub var data: CollectionData?
init(_ catalogMetadata: NFTCatalog.NFTCatalogMetadata?, _ collectionDisplay: MetadataViews.NFTCollectionDisplay?, _ collectionData: MetadataViews.NFTCollectionData?) {
self.display = nil
self.data = nil
self.inCatalog = false
if let c = catalogMetadata {
self.display = CollectionDisplay(c.collectionDisplay)
self.data = CollectionData(c.collectionData, nil)
self.inCatalog = true
return
}
if let c = collectionDisplay {
self.display = CollectionDisplay(c)
}
if let d = collectionData {
self.data = CollectionData(nil, d)
}
}
}
pub struct CollectionDisplay {
pub let name: String
pub let description: String
pub let externalURL: String
pub let squareImage: Media
pub let bannerImage: Media
pub let socials: {String: String}
init(_ c: MetadataViews.NFTCollectionDisplay) {
self.name = c.name
self.description = c.description
self.externalURL = c.externalURL.url
self.squareImage = Media(c.squareImage)
self.bannerImage = Media(c.bannerImage)
self.socials = {}
for k in c.socials.keys {
self.socials[k] = c.socials[k]!.url
}
}
}
pub struct Media {
pub let uri: String
pub let fileType: String
pub let mediaType: String
init(_ m: MetadataViews.Media) {
self.uri = m.file.uri()
self.fileType = m.file.getType().identifier
self.mediaType = m.mediaType
}
}
pub struct CollectionData {
pub var storagePath: StoragePath
pub var publicPath: PublicPath
init(_ catalogData: NFTCatalog.NFTCollectionData?, _ collectionData: MetadataViews.NFTCollectionData?) {
self.storagePath = /storage/empty
self.publicPath = /public/empty
if let c = catalogData {
self.storagePath = c.storagePath
self.publicPath = c.publicPath
return
} else if let c = collectionData {
self.storagePath = c.storagePath
self.publicPath = c.publicPath
return
} else {
panic("either catalogData or collection data must be non-nil")
}
}
}
}
Cadence Script
1transaction(name: String, code: String ) {
2 prepare(signer: AuthAccount) {
3 signer.contracts.add(name: name, code: code.utf8 )
4 }
5 }