DeploySEALED
╲!◆▓◆◆*?░■▒╲▒▫◆?░□╳■~●■○^░^░●▓▫!■◆#▫%○○▓#@█■@╳●▓&█○■▒!●■█$╳╲%*!▫
Transaction ID
Execution Fee
0.00000649 FLOWTransaction Summary
DeployContract deployment
Contract deployment
Script Arguments
0nameString
NTest_Trm_Asset_NFT
1codeString
import NonFungibleToken from 0x1d7e57aa55817448
import ViewResolver from 0x1d7e57aa55817448
import MetadataViews from 0x1d7e57aa55817448
access(all) contract NTest_Trm_Asset_NFT: NonFungibleToken {
access(all) var totalSupply: UInt64
/// Standard Paths
access(all) let CollectionStoragePath: StoragePath
access(all) let CollectionPublicPath: PublicPath
/// Path where the minter should be stored
/// The standard paths for the collection are stored in the collection resource type
access(all) let MinterStoragePath: StoragePath
access(all) let adminStoragePath: StoragePath
access(all) event AssetMinted(id: UInt64, title: String, description: String, thumbnail: String, metadata: {String: String}, serialNumber: UInt32, url: String, ownerInfo: String, assetType: String, kID: String, songID: String, masterTokenID: UInt64?, webhookID: String?)
access(all) event AssetOwnerTransfer(id: UInt64, ownerFrom: String, ownerTo: String, songID: String, price: UFix64?, priceUnit: String?, paymentRefInfo: String?, webhookID: String?)
access(all) event AssetBatchMinted(startID: UInt64, endID: UInt64, totalCount: UInt32, startSerialNumber: UInt32, endSerialNumber: UInt32, title: String, description: String, thumbnail: String, metadata: {String: String}, url: String, ownerInfo: String, assetType: String, kID: String, songID: String, masterTokenID: UInt64, webhookID: String?)
access(all) event AssetUpdated(id: UInt64 , title: String?, description: String?, thumbnail: String?, assetType: String?, ownerInfo: String, metadata: {String: String}?, webhookID: String? )
access(all) event AssetBatchUpdated(ids: [UInt64] , title: String?, description: String?, thumbnail: String?, assetType: String?, ownerInfo: String, metadata: {String: String}?, webhookID: String? )
access(all) resource NFT: NonFungibleToken.NFT {
access(all) let id: UInt64
access(all) let masterTokenID: UInt64
access(all) var title: String
access(all) var description: String
access(all) var thumbnail: String
access(all) let url: String
access(all) var ownerInfo: String
access(all) let serialNumber: UInt32
access(all) var assetType: String
access(all) let kID: String
access(all) var songID: String
access(all) var metadata: {String: AnyStruct}
init(
id: UInt64,
title: String,
description: String,
thumbnail: String,
metadata: {String: AnyStruct},
serialNumber: UInt32,
url: String,
ownerInfo: String,
assetType: String,
kID: String,
songID: String,
masterTokenID: UInt64
) {
self.id = id
self.title = title
self.description = description
self.thumbnail = thumbnail
self.serialNumber = serialNumber
self.url = url
self.ownerInfo = ownerInfo
self.assetType = assetType
self.kID = kID
self.songID = songID
self.masterTokenID = masterTokenID
self.metadata = metadata
}
access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
return <-NTest_Trm_Asset_NFT.createEmptyCollection(nftType: Type<@NTest_Trm_Asset_NFT.NFT>())
}
access(all) view fun getViews(): [Type] {
return [
Type<MetadataViews.Display>(),
Type<MetadataViews.ExternalURL>(),
Type<MetadataViews.Editions>(),
Type<MetadataViews.NFTCollectionData>(),
Type<MetadataViews.NFTCollectionDisplay>(),
Type<MetadataViews.Serial>()
]
}
access(all) fun resolveView(_ view: Type): AnyStruct? {
switch view {
case Type<MetadataViews.Display>():
return MetadataViews.Display(
name: self.title,
description: self.description,
thumbnail: MetadataViews.HTTPFile(
url: self.thumbnail
)
)
case Type<MetadataViews.Editions>():
// There is no max number of NFTs that can be minted from this contract
// so the max edition field value is set to nil
let editionInfo = MetadataViews.Edition(name: "Intertrust NFT Creation", number: self.id, max: nil)
let editionList: [MetadataViews.Edition] = [editionInfo]
return MetadataViews.Editions(
editionList
)
case Type<MetadataViews.Serial>():
return MetadataViews.Serial(
self.id
)
case Type<MetadataViews.ExternalURL>():
return MetadataViews.ExternalURL("https://www.intertrust.com/marketmaker/")
case Type<MetadataViews.NFTCollectionData>():
return NTest_Trm_Asset_NFT.resolveContractView(resourceType: Type<@NTest_Trm_Asset_NFT.NFT>(), viewType: Type<MetadataViews.NFTCollectionData>())
case Type<MetadataViews.NFTCollectionDisplay>():
return NTest_Trm_Asset_NFT.resolveContractView(resourceType: Type<@NTest_Trm_Asset_NFT.NFT>(), viewType: Type<MetadataViews.NFTCollectionDisplay>())
}
return nil
}
access(contract) fun transferOwner(id: UInt64, ownerFrom: String, ownerTo: String, songID: String, price: UFix64?, priceUnit: String?, paymentRefInfo: String?, webhookID: String?) {
if (ownerFrom == self.ownerInfo) {
self.ownerInfo = ownerTo
emit AssetOwnerTransfer(id: id, ownerFrom: ownerFrom, ownerTo: ownerTo, songID: songID, price: price, priceUnit: priceUnit, paymentRefInfo: paymentRefInfo, webhookID: webhookID)
}
}
access(contract) fun updateMetadata(id: UInt64 , title: String?, description: String?, thumbnail: String?, assetType: String?, ownerInfo: String, metadata: {String: String}?, webhookID: String? ){
if (ownerInfo == self.ownerInfo) {
if let tempname = title {self.title = tempname}
if let tempdesc = description {self.description = tempdesc}
if let tempthumbnail = thumbnail {self.thumbnail = tempthumbnail}
if let tempassetType = assetType {self.assetType = tempassetType}
if let tempmetadata = metadata {self.metadata = tempmetadata}
}
}
}
access(all) resource Collection: NonFungibleToken.Collection {
/// dictionary of NFT conforming tokens
/// NFT is a resource type with an `UInt64` ID field
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
init () {
self.ownedNFTs <- {}
}
access(all) view fun getSupportedNFTTypes(): {Type: Bool} {
let supportedTypes: {Type: Bool} = {}
supportedTypes[Type<@NTest_Trm_Asset_NFT.NFT>()] = true
return supportedTypes
}
/// Returns whether or not the given type is accepted by the collection
/// A collection that can accept any type should just return true by default
access(all) view fun isSupportedNFTType(type: Type): Bool {
return type == Type<@NTest_Trm_Asset_NFT.NFT>()
}
access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
let token <- self.ownedNFTs.remove(key: withdrawID)
?? panic("Could not withdraw an NFT with the provided ID from the collection")
return <-token
}
/// deposit takes a NFT and adds it to the collections dictionary
/// and adds the ID to the id array
access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
pre {
false: "Depositing Asset directly to Asset contract is not allowed"
}
let token <- token as! @NTest_Trm_Asset_NFT.NFT
let id = token.id
// add the new token to the dictionary which removes the old one
let oldToken <- self.ownedNFTs[token.id] <- token
destroy oldToken
}
access(all) view fun getIDs(): [UInt64] {
return self.ownedNFTs.keys
}
/// Gets the amount of NFTs stored in the collection
access(all) view fun getLength(): Int {
return self.ownedNFTs.length
}
access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
return (&self.ownedNFTs[id])
}
/// Borrow the view resolver for the specified NFT ID
access(all) view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}? {
if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
return nft as &{ViewResolver.Resolver}
}
return nil
}
access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
return <-NTest_Trm_Asset_NFT.createEmptyCollection(nftType: Type<@NTest_Trm_Asset_NFT.NFT>())
}
access(all) view fun getSerialNumber(id: UInt64): UInt32 {
pre {
self.ownedNFTs[id] != nil: "Asset Token ID does not exist"
}
let refNFT = (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
let refAssetNFT: &NTest_Trm_Asset_NFT.NFT = refNFT as! &NFT
return refAssetNFT.serialNumber
}
access(all) view fun getownerInfo(id: UInt64): String {
pre {
self.ownedNFTs[id] != nil: "Asset Token ID does not exist"
}
let refNFT = (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
let refAssetNFT = refNFT as! &NFT
return refAssetNFT.ownerInfo
}
access(all) view fun getkID(id: UInt64): String {
pre {
self.ownedNFTs[id] != nil: "Asset Token ID does not exist"
}
let refNFT = (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
let refAssetNFT = refNFT as! &NFT
return refAssetNFT.kID
}
access(contract) fun depositAsset(token: @{NonFungibleToken.NFT}) {
let assetToken <- token as! @NFT
let oldToken <- self.ownedNFTs[assetToken.id] <- assetToken
destroy oldToken
}
access(contract) fun transferOwner(id: UInt64, ownerFrom: String, ownerTo: String, songID: String, price: UFix64?, priceUnit: String?, paymentRefInfo: String?, webhookID: String?) {
pre {
self.ownedNFTs[id] != nil: "Asset Token ID does not exist"
}
let refNFT = (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
let refAssetNFT = refNFT as! &NFT
refAssetNFT.transferOwner(id: id, ownerFrom: ownerFrom, ownerTo: ownerTo, songID: songID, price: price, priceUnit: priceUnit, paymentRefInfo: paymentRefInfo, webhookID: webhookID)
}
access(contract) fun updateMetadata(id: UInt64, title: String?, description: String?, thumbnail: String?, assetType: String?, ownerInfo: String, metadata: {String:String}?, webhookID: String?) {
pre {
self.ownedNFTs[id] != nil: "Asset Token ID does not exist"
}
let refNFT = (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
let refAssetNFT = refNFT as! &NFT
refAssetNFT.updateMetadata(id: id, title: title, description: description, thumbnail: thumbnail, assetType: assetType, ownerInfo: ownerInfo, metadata: metadata, webhookID:webhookID)
emit AssetUpdated(id: id, title: title, description: description, thumbnail: thumbnail, assetType: assetType, ownerInfo: ownerInfo, metadata: metadata, webhookID: webhookID)
}
access(contract) fun batchupdateMetadata(ids: [UInt64], title: String?, description: String?, thumbnail: String?, assetType: String?, ownerInfo: String, metadata: {String:String}?, webhookID: String?) {
pre {
assetType == "private" || assetType == "public" || assetType == nil:
"Asset Type must be private or public or null"
ids.length > 0: "Total length of ids cannot be less than 1"
}
for id in ids {
if self.ownedNFTs[id] != nil {
let refNFT = (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
let refAssetNFT = refNFT as! &NFT
refAssetNFT.updateMetadata(id: id, title: title, description: description, thumbnail: thumbnail, assetType: assetType, ownerInfo: ownerInfo, metadata: metadata, webhookID:webhookID)
} else {
panic("Asset Token ID ".concat(id.toString()).concat(" not owned"))
}
}
emit AssetBatchUpdated(ids: ids, title: title, description: description, thumbnail: thumbnail, assetType: assetType, ownerInfo: ownerInfo, metadata: metadata, webhookID: webhookID)
}
}
access(all) fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection} {
return <- create Collection()
}
access(all) view fun getContractViews(resourceType: Type?): [Type] {
return [
Type<MetadataViews.NFTCollectionData>(),
Type<MetadataViews.NFTCollectionDisplay>()
]
}
access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
switch viewType {
case Type<MetadataViews.NFTCollectionData>():
let collectionData = MetadataViews.NFTCollectionData(
storagePath: self.CollectionStoragePath,
publicPath: self.CollectionPublicPath,
publicCollection: Type<&NTest_Trm_Asset_NFT.Collection>(),
publicLinkedType: Type<&NTest_Trm_Asset_NFT.Collection>(),
createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
return <-NTest_Trm_Asset_NFT.createEmptyCollection(nftType: Type<@NTest_Trm_Asset_NFT.NFT>())
})
)
return collectionData
case Type<MetadataViews.NFTCollectionDisplay>():
let media = MetadataViews.Media(
file: MetadataViews.HTTPFile(
url: "https://www.intertrust.com/wp-content/themes/flat-theme/assets/images/svg/intertrust-header-logoV2.png"
),
mediaType: "image/png+xml"
)
return MetadataViews.NFTCollectionDisplay(
name: "The Example Collection",
description: "This collection is used as an example to help you develop your next Flow NFT.",
externalURL: MetadataViews.ExternalURL("https://www.intertrust.com/marketmaker/"),
squareImage: media,
bannerImage: media,
socials: {
"twitter": MetadataViews.ExternalURL("https://x.com/IntertrustTech")
}
)
}
return nil
}
access(all) resource NFTMinter {
/// mintNFT mints a new NFT with a new ID
/// and returns it to the calling context
access(all) fun mintNFT(
collectionRef: &NTest_Trm_Asset_NFT.Collection,
title: String,
description: String,
thumbnail: String,
metadata: {String: String},
serialNumber: UInt32,
url: String,
ownerInfo: String,
assetType: String,
kID: String,
songID: String,
masterTokenID: UInt64?,
webhookID: String?
): UInt64 {
let tokenID = NTest_Trm_Asset_NFT.totalSupply
var finalMasterTokenID = tokenID
if let tempMasterTokenID = masterTokenID {
var masterTokenSerialNumber = collectionRef.getSerialNumber(id: tempMasterTokenID)
if masterTokenSerialNumber != 0 { panic("Invalid Master Token ID") }
finalMasterTokenID = tempMasterTokenID
}
collectionRef.deposit(token: <- create NFT(id: tokenID,
title: title,
description: description,
thumbnail: thumbnail,
metadata: metadata,
serialNumber: serialNumber,
url: url,
ownerInfo: ownerInfo,
assetType: assetType,
kID: kID,
songID: songID,
masterTokenID: finalMasterTokenID))
NTest_Trm_Asset_NFT.totalSupply = tokenID + 1
return NTest_Trm_Asset_NFT.totalSupply
// create a new NFT
}
}
access(all) resource Admin {
access(all) fun transferOwner(collectionRef: &NTest_Trm_Asset_NFT.Collection, id: UInt64, ownerFrom: String, ownerTo: String, songID: String, price: UFix64?, priceUnit: String?, paymentRefInfo: String?, webhookID: String?) {
collectionRef.transferOwner(id: id, ownerFrom: ownerFrom, ownerTo: ownerTo, songID: songID, price: price, priceUnit: priceUnit, paymentRefInfo: paymentRefInfo, webhookID: webhookID)
}
access(all) fun updateMetadata(collectionRef: &NTest_Trm_Asset_NFT.Collection, id: UInt64, title: String?, description: String?, thumbnail: String?, metadata: {String:String}?, ownerInfo: String, assetType: String?, webhookID: String?) {
collectionRef.updateMetadata(id: id, title: title, description: description, thumbnail: thumbnail, assetType: assetType, ownerInfo: ownerInfo, metadata: metadata, webhookID: webhookID)
}
access(all) fun batchupdateMetadata(collectionRef: &NTest_Trm_Asset_NFT.Collection, ids: [UInt64], title: String?, description: String?, thumbnail: String?, metadata: {String:String}?, ownerInfo: String, assetType: String?, webhookID: String?) {
collectionRef.batchupdateMetadata(ids: ids, title: title, description: description, thumbnail: thumbnail, assetType: assetType, ownerInfo: ownerInfo, metadata: metadata, webhookID: webhookID)
}
access(all) fun depositAsset(collectionRef: &NTest_Trm_Asset_NFT.Collection,title: String, description: String, thumbnail: String, metadata: {String: String}, serialNumber: UInt32, url: String,ownerInfo: String, assetType: String, kID: String,songID: String, masterTokenID: UInt64?,webhookID: String?): UInt64 {
let tokenID = NTest_Trm_Asset_NFT.totalSupply
var finalMasterTokenID = tokenID
if let tempMasterTokenID = masterTokenID {
var masterTokenSerialNumber = collectionRef.getSerialNumber(id: tempMasterTokenID)
if masterTokenSerialNumber != 0 { panic("Invalid Master Token ID") }
finalMasterTokenID = tempMasterTokenID
}
collectionRef.depositAsset(token: <- create NFT(id: tokenID, title: title, description: description, thumbnail: thumbnail, metadata: metadata, serialNumber: serialNumber, url: url, ownerInfo: ownerInfo, assetType: assetType,kID: kID, songID: songID, masterTokenID: finalMasterTokenID))
NTest_Trm_Asset_NFT.totalSupply = tokenID + 1
emit AssetMinted(id: tokenID, title: title, description: description, thumbnail: thumbnail, metadata: metadata, serialNumber: serialNumber, url: url, ownerInfo: ownerInfo, assetType: assetType, kID: kID, songID: songID,masterTokenID: finalMasterTokenID, webhookID: webhookID)
return NTest_Trm_Asset_NFT.totalSupply
// create a new NFT
}
access(all) fun batchdepositAsset(collectionRef: &NTest_Trm_Asset_NFT.Collection, totalCount: UInt32, title: String, description: String, thumbnail: String, metadata: {String: String},startSerialNumber: UInt32, url: String, ownerInfo: String, assetType: String, kID: String, songID: String, masterTokenID: UInt64?, webhookID: String?): UInt64 {
pre {
totalCount > 0: "Total Count cannot be less than 1"
}
let startTokenID = NTest_Trm_Asset_NFT.totalSupply
var tempmasterTokenID = startTokenID
if masterTokenID != nil {
tempmasterTokenID = masterTokenID!
}
var tokenID = startTokenID
var counter: UInt32 = 0
var serialNumber = startSerialNumber
while counter < totalCount {
collectionRef.depositAsset(token: <- create NFT(id: tokenID, title: title, description: description, thumbnail: thumbnail, metadata: metadata, serialNumber: serialNumber, url: url, ownerInfo: ownerInfo, assetType: assetType, kID: kID, songID: songID, masterTokenID: tempmasterTokenID))
counter = counter + 1
tokenID = tokenID + 1
serialNumber = serialNumber + 1
}
let endTokenID = tokenID - 1
let endSerialNumber = serialNumber - 1
emit AssetBatchMinted(startID: startTokenID, endID: endTokenID, totalCount: totalCount, startSerialNumber: startSerialNumber, endSerialNumber: endSerialNumber, title: title, description: description, thumbnail: thumbnail, metadata: metadata, url: url, ownerInfo: ownerInfo, assetType: assetType, kID: kID, songID: songID, masterTokenID: tempmasterTokenID, webhookID: webhookID)
NTest_Trm_Asset_NFT.totalSupply = tokenID
return NTest_Trm_Asset_NFT.totalSupply
}
}
init() {
// Set the named paths
self.CollectionStoragePath = /storage/NTest_Trm_Asset_NFTCollection
self.CollectionPublicPath = /public/NTest_Trm_Asset_NFTCollection
self.MinterStoragePath = /storage/NTest_Trm_Asset_NFTMinter
self.adminStoragePath = /storage/NTest_Trm_Asset_NFTAdmin
// First, check to see if a minter resource already exists
if self.account.storage.type(at: self.MinterStoragePath) == nil {
// Put the minter in storage with access only to admin
self.account.storage.save(<-create NFTMinter(), to: self.MinterStoragePath)
}
// First, check to see if a minter resource already exists
if self.account.storage.type(at: self.adminStoragePath) == nil {
// Put the minter in storage with access only to admin
self.account.storage.save(<-create Admin(), to: self.adminStoragePath)
}
self.totalSupply = 0
}
}
Cadence Script
1transaction(name: String, code: String ) {
2 prepare(signer: auth(AddContract) &Account) {
3 signer.contracts.add(name: name, code: code.utf8 )
4 }
5 }