Smart Contract

TMAUNFT

A.a355799993b95813.TMAUNFT

Deployed

3d ago
Feb 25, 2026, 01:16:17 PM UTC

Dependents

5 imports
1// Description: Smart Contract for Ticketmaster Digital Collectibles
2// SPDX-License-Identifier: UNLICENSED
3
4import NonFungibleToken from 0x1d7e57aa55817448
5import MetadataViews from 0x1d7e57aa55817448
6import ViewResolver from 0x1d7e57aa55817448
7
8access(all) contract TMAUNFT : NonFungibleToken {
9
10    access(all) var totalSupply: UInt64
11
12    access(all) event ContractInitialized()
13    access(all) event Withdraw(id: UInt64, from: Address?)
14    access(all) event Deposit(id: UInt64, to: Address?)
15
16    access(all) let CollectionStoragePath: StoragePath
17    access(all) let CollectionPublicPath: PublicPath
18    access(all) let MinterStoragePath: StoragePath
19
20    // Correct type from NonFungibleToken.INFT to NonFungibleToken.NFT
21    access(all) resource NFT : NonFungibleToken.NFT {
22        access(all) let id: UInt64
23        access(all) var link: String
24        access(all) var batch: UInt32
25        access(all) var sequence: UInt16
26        access(all) var limit: UInt16
27
28        init(
29            initID: UInt64,
30            initlink: String,
31            initbatch: UInt32,
32            initsequence: UInt16,
33            initlimit: UInt16
34        ) {
35            self.id = initID
36            self.link = initlink
37            self.batch = initbatch
38            self.sequence = initsequence
39            self.limit = initlimit
40        }
41        /// createEmptyCollection creates an empty Collection
42        /// and returns it to the caller so that they can own NFTs
43        /// @{NonFungibleToken.Collection}
44        access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
45            return <-TMAUNFT.createEmptyCollection(nftType: Type<@TMAUNFT.NFT>())
46        }
47        access(all) view fun getViews(): [Type] {
48            return [
49                Type<MetadataViews.NFTCollectionData>()
50            ]
51        }
52
53        access(all) fun resolveView(_ view: Type): AnyStruct? {
54            switch view {
55                case Type<MetadataViews.NFTCollectionData>():
56                    return TMAUNFT.resolveContractView(resourceType: Type<@TMAUNFT.NFT>(), viewType: Type<MetadataViews.NFTCollectionData>())
57            }
58            return nil
59        }
60    }
61
62    access(all) resource interface TMAUNFTCollectionPublic {
63        // Deprecated, only here for backwards compatibility
64    }
65
66    access(all) resource Collection : NonFungibleToken.Collection, TMAUNFTCollectionPublic {
67        access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
68
69        init() {
70            self.ownedNFTs <- {}
71        }
72
73        access(all) view fun getSupportedNFTTypes(): {Type: Bool} {
74            let supportedTypes: {Type: Bool} = {}
75            supportedTypes[Type<@TMAUNFT.NFT>()] = true
76            return supportedTypes
77        }
78
79        access(all) view fun isSupportedNFTType(type: Type): Bool {
80            return type == Type<@TMAUNFT.NFT>()
81        }
82
83        access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
84            let token <- self.ownedNFTs.remove(key: withdrawID)
85                ?? panic("Could not withdraw an NFT with the provided ID from the collection")
86
87            return <-token
88        }
89
90        access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
91            let token <- token as! @TMAUNFT.NFT
92            let id = token.id
93
94            let oldToken <- self.ownedNFTs[token.id] <- token
95
96            destroy oldToken
97        }
98
99        access(all) view fun getIDs(): [UInt64] {
100            return self.ownedNFTs.keys
101        }
102
103        access(all) view fun getLength(): Int {
104            return self.ownedNFTs.length
105        }
106
107        access(all) view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}? {
108            if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
109                return nft as &{ViewResolver.Resolver}
110            }
111            return nil
112        }
113
114        access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
115            return (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)
116        }
117
118        access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
119            return <- TMAUNFT.createEmptyCollection(nftType: Type<@TMAUNFT.NFT>())
120        }
121    }
122
123    access(all) fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection} {
124        return <- create Collection()
125    }
126
127    access(all) view fun getContractViews(resourceType: Type?): [Type] {
128        return [
129            Type<MetadataViews.NFTCollectionData>(),
130            Type<MetadataViews.NFTCollectionDisplay>(),
131            Type<MetadataViews.EVMBridgedMetadata>()
132        ]
133    }
134
135    access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
136        switch viewType {
137            case Type<MetadataViews.NFTCollectionData>():
138                let collectionData = MetadataViews.NFTCollectionData(
139                    storagePath: self.CollectionStoragePath,
140                    publicPath: self.CollectionPublicPath,
141                    publicCollection: Type<&TMAUNFT.Collection>(),
142                    publicLinkedType: Type<&TMAUNFT.Collection>(),
143                    createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
144                        return <-TMAUNFT.createEmptyCollection(nftType: Type<@TMAUNFT.NFT>())
145                    })
146                )
147                return collectionData
148            case Type<MetadataViews.NFTCollectionDisplay>():
149                let media = MetadataViews.Media(
150                    file: MetadataViews.HTTPFile(
151                        url: "https://assets.website-files.com/5f6294c0c7a8cdd643b1c820/5f6294c0c7a8cda55cb1c936_Flow_Wordmark.svg"
152                    ),
153                    mediaType: "image/svg+xml"
154                )
155                return MetadataViews.NFTCollectionDisplay(
156                    name: "Ticketmaster Collection",
157                    description: "This collection represents Ticketmaster Digital Collectibles.",
158                    externalURL: MetadataViews.ExternalURL("https://ticketmaster-nft.onflow.org"),
159                    squareImage: media,
160                    bannerImage: media,
161                    socials: {
162                        "twitter": MetadataViews.ExternalURL("https://twitter.com/ticketmaster")
163                    }
164                )
165            case Type<MetadataViews.EVMBridgedMetadata>():
166                return MetadataViews.EVMBridgedMetadata(
167                    name: "TMAUNFT",
168                    symbol: "TMAUNFT",
169                    uri: MetadataViews.URI(
170                        baseURI: nil,
171                        value: "https://ticketmaster-nft.onflow.org/contract-metadata.json"
172                    )
173                )
174        }
175        return nil
176    }
177
178    access(all) resource NFTMinter {
179
180        access(all) fun mintNFT(
181            glink: String,
182            gbatch: UInt32,
183            glimit: UInt16,
184            gsequence: UInt16
185        ): @TMAUNFT.NFT {
186
187            let tokenID = (UInt64(gbatch) << 32) | (UInt64(glimit) << 16) | UInt64(gsequence)
188
189            let metadata: {String: AnyStruct} = {}
190            let currentBlock = getCurrentBlock()
191            metadata["mintedBlock"] = currentBlock.height
192            metadata["mintedTime"] = currentBlock.timestamp
193            metadata["foo"] = "bar"
194
195            var newNFT <- create NFT(
196                initID: tokenID,
197                initlink: glink,
198                initbatch: gbatch,
199                initsequence: gsequence,
200                initlimit: glimit
201            )
202            TMAUNFT.totalSupply = TMAUNFT.totalSupply + 1
203            return <-newNFT
204        }
205    }
206
207    init() {
208        self.CollectionStoragePath = /storage/TMAUNFTCollection
209        self.CollectionPublicPath = /public/TMAUNFTCollection
210        self.MinterStoragePath = /storage/TMAUNFTMinter
211        self.totalSupply = 0
212
213        let collection <- create Collection()
214        self.account.storage.save(<-collection, to: self.CollectionStoragePath)
215
216        let collectionCap = self.account.capabilities.storage.issue<&TMAUNFT.Collection>(self.CollectionStoragePath)
217        self.account.capabilities.publish(collectionCap, at: self.CollectionPublicPath)
218
219        let minter <- create NFTMinter()
220        self.account.storage.save(<-minter, to: self.MinterStoragePath)
221    }
222}
223