Smart Contract
MatrixWorldFlowFestNFT
A.2d2750f240198f91.MatrixWorldFlowFestNFT
1import NonFungibleToken from 0x1d7e57aa55817448
2import ViewResolver from 0x1d7e57aa55817448
3import MetadataViews from 0x1d7e57aa55817448
4import FungibleToken from 0xf233dcee88fe0abe
5
6access(all) contract MatrixWorldFlowFestNFT: NonFungibleToken {
7 access(all) event ContractInitialized()
8 access(all) event Withdraw(id: UInt64, from: Address?)
9 access(all) event Deposit(id: UInt64, to: Address?)
10 access(all) event Minted(id: UInt64, name: String, description:String, animationUrl:String, hash: String, type: String)
11
12 access(all) let CollectionStoragePath: StoragePath
13 access(all) let CollectionPublicPath: PublicPath
14 access(all) let MinterStoragePath: StoragePath
15
16 access(all) var totalSupply: UInt64
17
18 access(all) resource interface NFTPublic {
19 access(all) let id: UInt64
20 access(all) let metadata: Metadata
21 }
22
23 access(all) struct Metadata {
24 access(all) let name: String
25 access(all) let description: String
26 access(all) let animationUrl: String
27 access(all) let hash: String
28 access(all) let type: String
29
30 init(name: String, description: String, animationUrl: String, hash: String, type: String) {
31 self.name = name
32 self.description = description
33 self.animationUrl = animationUrl
34 self.hash = hash
35 self.type = type
36 }
37 }
38
39 access(all) resource NFT: NonFungibleToken.NFT, NFTPublic {
40 access(all) let id: UInt64
41 access(all) let metadata: Metadata
42 init(initID: UInt64,metadata: Metadata) {
43 self.id = initID
44 self.metadata=metadata
45 }
46
47 access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
48 return <- create Collection()
49 }
50
51 access(all) view fun getViews(): [Type] {
52 return [
53 Type<MetadataViews.Display>(),
54 Type<MetadataViews.ExternalURL>(),
55 Type<MetadataViews.Serial>(),
56 Type<MetadataViews.NFTCollectionData>(),
57 Type<MetadataViews.NFTCollectionDisplay>(),
58 Type<MetadataViews.EVMBridgedMetadata>(),
59 Type<MetadataViews.Royalties>()
60 ]
61 }
62
63 access(all) fun resolveView(_ view: Type): AnyStruct? {
64 switch view {
65 case Type<MetadataViews.Display>():
66 return MetadataViews.Display(
67 name: self.metadata.name,
68 description: self.metadata.description,
69 thumbnail: MetadataViews.HTTPFile(
70 url:self.metadata.animationUrl
71 )
72 )
73 case Type<MetadataViews.Royalties>():
74 return MetadataViews.Royalties([])
75 case Type<MetadataViews.Serial>():
76 return MetadataViews.Serial(self.id)
77 case Type<MetadataViews.ExternalURL>():
78 return MetadataViews.ExternalURL("https://www.world3.ai")
79 case Type<MetadataViews.NFTCollectionData>():
80 return MatrixWorldFlowFestNFT.resolveContractView(resourceType: Type<@MatrixWorldFlowFestNFT.NFT>(), viewType: Type<MetadataViews.NFTCollectionData>())
81 case Type<MetadataViews.NFTCollectionDisplay>():
82 return MatrixWorldFlowFestNFT.resolveContractView(resourceType: Type<@MatrixWorldFlowFestNFT.NFT>(), viewType: Type<MetadataViews.NFTCollectionDisplay>())
83 case Type<MetadataViews.EVMBridgedMetadata>():
84 return MetadataViews.EVMBridgedMetadata(
85 name: "MatrixWorldFlowFestNFT",
86 symbol: "MWFF",
87 uri: MetadataViews.URI(
88 baseURI: self.metadata.animationUrl, // defining baseURI results in a concatenation of baseURI and value
89 value: ""
90 )
91 )
92
93 }
94 return nil
95 }
96 }
97
98 access(all) resource interface MatrixWorldFlowFestNFTCollectionPublic {}
99
100 access(all) resource Collection: MatrixWorldFlowFestNFTCollectionPublic, NonFungibleToken.Collection {
101 access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
102
103 init () {
104 self.ownedNFTs <- {}
105 }
106
107 /// getSupportedNFTTypes returns a list of NFT types that this receiver accepts
108 access(all) view fun getSupportedNFTTypes(): {Type: Bool} {
109 let supportedTypes: {Type: Bool} = {}
110 supportedTypes[Type<@MatrixWorldFlowFestNFT.NFT>()] = true
111 return supportedTypes
112 }
113
114 /// Returns whether or not the given type is accepted by the collection
115 /// A collection that can accept any type should just return true by default
116 access(all) view fun isSupportedNFTType(type: Type): Bool {
117 return type == Type<@MatrixWorldFlowFestNFT.NFT>()
118 }
119
120 access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
121 let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT")
122
123 emit Withdraw(id: token.id, from: self.owner?.address)
124
125 return <-token
126 }
127
128 access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
129 let token <- token as! @MatrixWorldFlowFestNFT.NFT
130
131 let id: UInt64 = token.id
132
133 let oldToken <- self.ownedNFTs[id] <- token
134
135 emit Deposit(id: id, to: self.owner?.address)
136
137 destroy oldToken
138 }
139
140 access(all) view fun getIDs(): [UInt64] {
141 return self.ownedNFTs.keys
142 }
143
144 /// Gets the amount of NFTs stored in the collection
145 access(all) view fun getLength(): Int {
146 return self.ownedNFTs.length
147 }
148
149 access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
150 return &self.ownedNFTs[id]
151 }
152
153 /// Borrow the view resolver for the specified NFT ID
154 access(all) view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}? {
155 if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
156 return nft as &{ViewResolver.Resolver}
157 }
158 return nil
159 }
160
161 access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
162 return <- create Collection()
163 }
164 }
165
166 access(all) view fun getContractViews(resourceType: Type?): [Type] {
167 return [
168 Type<MetadataViews.NFTCollectionData>(),
169 Type<MetadataViews.NFTCollectionDisplay>(),
170 Type<MetadataViews.EVMBridgedMetadata>()
171 ]
172 }
173
174 access(all) fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection} {
175 return <- create Collection()
176 }
177
178 access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
179 switch viewType {
180 case Type<MetadataViews.NFTCollectionData>():
181 let collectionsData = MetadataViews.NFTCollectionData(
182 storagePath: self.CollectionStoragePath,
183 publicPath: self.CollectionPublicPath,
184 publicCollection: Type<&MatrixWorldFlowFestNFT.Collection>(),
185 publicLinkedType: Type<&MatrixWorldFlowFestNFT.Collection>(),
186 createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
187 return <-MatrixWorldFlowFestNFT.createEmptyCollection(nftType: Type<@MatrixWorldFlowFestNFT.NFT>())
188 })
189 )
190 return collectionsData
191 case Type<MetadataViews.NFTCollectionDisplay>():
192 let squareMedia= MetadataViews.Media(
193 file: MetadataViews.HTTPFile(
194 url: "https://world3.ai/assets/WORLD3Logo_black.png"
195 ),
196 mediaType: "image/png"
197 )
198 let bannerMedia= MetadataViews.Media(
199 file: MetadataViews.HTTPFile(
200 url: "https://world3.ai/assets/Matrixworld_poster.png"
201 ),
202 mediaType: "image/png"
203 )
204 return MetadataViews.NFTCollectionDisplay(
205 name: "WORLD3 WORLD FLOW FEST",
206 description: "WORLD3 is an AI-Powered Autonomous World that acts as a social space and entertainment hub where users can PLAY, CREATE, and CONNECT.",
207 externalURL: MetadataViews.ExternalURL("https://world3.ai/"),
208 squareImage: squareMedia,
209 bannerImage: bannerMedia,
210 socials: {
211 "twitter": MetadataViews.ExternalURL("https://x.com/WORLD3_AI")
212 }
213 )
214 case Type<MetadataViews.EVMBridgedMetadata>():
215 return MetadataViews.EVMBridgedMetadata(
216 name: "WORLD3 WORLD FLOW FEST",
217 symbol: "MWA",
218 uri: MetadataViews.URI(
219 baseURI: "https://world3.ai",
220 value: ""
221 )
222 )
223 default:
224 return nil
225 }
226 }
227
228 access(all) struct NftData {
229 access(all) let metadata: MatrixWorldFlowFestNFT.Metadata
230 access(all) let id: UInt64
231 init(metadata: MatrixWorldFlowFestNFT.Metadata, id: UInt64) {
232 self.metadata= metadata
233 self.id=id
234 }
235 }
236
237 access(all) resource NFTMinter {
238 access(all) fun mintNFT(
239 recipient: &{NonFungibleToken.CollectionPublic},
240 name: String,
241 description: String,
242 animationUrl: String,
243 hash: String,
244 type: String) {
245 emit Minted(id: MatrixWorldFlowFestNFT.totalSupply, name: name, description: description, animationUrl: animationUrl, hash: hash, type: type)
246
247 recipient.deposit(token: <-create MatrixWorldFlowFestNFT.NFT(
248 initID: MatrixWorldFlowFestNFT.totalSupply,
249 metadata: Metadata(
250 name: name,
251 description:description,
252 animationUrl: animationUrl,
253 hash: hash,
254 type: type
255 )))
256
257 MatrixWorldFlowFestNFT.totalSupply = MatrixWorldFlowFestNFT.totalSupply + (1 as UInt64)
258 }
259 }
260
261 init() {
262 self.CollectionStoragePath = /storage/MatrixWorldFlowFestNFTCollection
263 self.CollectionPublicPath = /public/MatrixWorldFlowFestNFTCollection
264 self.MinterStoragePath = /storage/MatrixWorldFlowFestNFTrMinter
265
266 self.totalSupply = 0
267
268 let minter <- create NFTMinter()
269 self.account.storage.save(<-minter, to: self.MinterStoragePath)
270
271 emit ContractInitialized()
272 }
273}
274
275