Smart Contract

InceptionBlackBox

A.83ed64a1d4f3833f.InceptionBlackBox

Deployed

6d ago
Feb 21, 2026, 06:59:56 PM UTC

Dependents

3347 imports
1// SPDX-License-Identifier: MIT
2import NonFungibleToken from 0x1d7e57aa55817448
3import ViewResolver from 0x1d7e57aa55817448
4import MetadataViews from 0x1d7e57aa55817448
5
6access(all)
7contract InceptionBlackBox: NonFungibleToken{ 
8	access(all)
9	event ContractInitialized()
10	
11	access(all)
12	event Withdraw(id: UInt64, from: Address?)
13	
14	access(all)
15	event Deposit(id: UInt64, to: Address?)
16	
17	access(all)
18	event Minted(id: UInt64)
19	
20	access(all)
21	event Opened(id: UInt64)
22	
23	access(all)
24	let CollectionStoragePath: StoragePath
25	
26	access(all)
27	let CollectionPublicPath: PublicPath
28	
29	access(all)
30	let AdminStoragePath: StoragePath
31	
32	access(all)
33	var totalSupply: UInt64
34	
35	access(all)
36	var crystalPrice: UInt64
37	
38	access(all)
39	var mintLimit: UInt64
40	
41	access(all)
42	var InceptionBlackBoxMetadata: InceptionBlackBoxTemplate
43	
44	access(all)
45	resource interface InceptionBlackBoxCollectionPublic{ 
46		access(all)
47		fun deposit(token: @{NonFungibleToken.NFT}): Void
48		
49		access(all)
50		view fun getIDs(): [UInt64]
51		
52		access(all)
53		view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}?
54		
55		access(all)
56		fun borrowInceptionBlackBox(id: UInt64): &InceptionBlackBox.NFT?{ 
57			post{ 
58				result == nil || result?.id == id:
59					"Cannot borrow InceptionBlackBox reference: The ID of the returned reference is incorrect"
60			}
61		}
62	}
63	
64	access(all)
65	struct InceptionBlackBoxTemplate{ 
66		access(all)
67		var name: String
68		
69		access(all)
70		var description: String
71		
72		access(self)
73		var metadata:{ String: String}
74		
75		access(all)
76		fun getMetadata():{ String: String}{ 
77			return self.metadata
78		}
79		
80		access(all)
81		fun updateMetadata(newMetadata:{ String: String}){ 
82			pre{ 
83				newMetadata.length != 0:
84					"New Template metadata cannot be empty"
85			}
86			self.metadata = newMetadata
87		}
88		
89		init(name: String, description: String, metadata:{ String: String}){ 
90			self.name = name
91			self.description = description
92			self.metadata = metadata
93		}
94	}
95	
96	access(all)
97	resource NFT: NonFungibleToken.NFT, ViewResolver.Resolver{ 
98		access(all)
99		let id: UInt64
100		
101		access(all)
102		let serialNumber: UInt64
103		
104		access(all)
105		view fun getViews(): [Type]{ 
106			return [Type<MetadataViews.Display>()]
107		}
108		
109		access(all)
110		fun resolveView(_ view: Type): AnyStruct?{ 
111			switch view{ 
112				case Type<MetadataViews.Display>():
113					return MetadataViews.Display(name: InceptionBlackBox.InceptionBlackBoxMetadata.name, description: InceptionBlackBox.InceptionBlackBoxMetadata.description, thumbnail: MetadataViews.HTTPFile(url: (InceptionBlackBox.InceptionBlackBoxMetadata.getMetadata()!)["uri"]!))
114			}
115			return nil
116		}
117		
118		access(all)
119		fun getNFTMetadata(): InceptionBlackBoxTemplate{ 
120			return InceptionBlackBox.InceptionBlackBoxMetadata
121		}
122		
123		access(all)
124		fun createEmptyCollection(): @{NonFungibleToken.Collection}{ 
125			return <-create Collection()
126		}
127		
128		init(initID: UInt64, serialNumber: UInt64){ 
129			self.id = initID
130			self.serialNumber = serialNumber
131		}
132	}
133	
134	access(all)
135	resource Collection: InceptionBlackBoxCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.Collection, NonFungibleToken.CollectionPublic, ViewResolver.ResolverCollection{ 
136		access(all)
137		var ownedNFTs: @{UInt64:{ NonFungibleToken.NFT}}
138		
139		access(NonFungibleToken.Withdraw)
140		fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT}{ 
141			let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT")
142			emit Withdraw(id: token.id, from: self.owner?.address)
143			return <-token
144		}
145		
146		access(all)
147		fun deposit(token: @{NonFungibleToken.NFT}): Void{ 
148			let token <- token as! @InceptionBlackBox.NFT
149			let id: UInt64 = token.id
150			let oldToken <- self.ownedNFTs[id] <- token
151			emit Deposit(id: id, to: self.owner?.address)
152			destroy oldToken
153		}
154		
155		access(all)
156		fun batchDeposit(collection: @Collection){ 
157			let keys = collection.getIDs()
158			for key in keys{ 
159				self.deposit(token: <-collection.withdraw(withdrawID: key))
160			}
161			destroy collection
162		}
163		
164		access(all)
165		view fun getIDs(): [UInt64]{ 
166			return self.ownedNFTs.keys
167		}
168		
169		access(all)
170		view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}?{ 
171			return (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
172		}
173		
174		access(all)
175		fun borrowInceptionBlackBox(id: UInt64): &InceptionBlackBox.NFT?{ 
176			if self.ownedNFTs[id] != nil{ 
177				let ref = (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
178				return ref as! &InceptionBlackBox.NFT
179			} else{ 
180				return nil
181			}
182		}
183		
184		access(all)
185		view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}?{ 
186			let nft = (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
187			let exampleNFT = nft as! &InceptionBlackBox.NFT
188			return exampleNFT as &{ViewResolver.Resolver}
189		}
190		
191		access(all)
192		fun openBox(tokenID: UInt64){ 
193			let token <- self.ownedNFTs.remove(key: tokenID) ?? panic("missing NFT")
194			emit Opened(id: token.id)
195			destroy <-token
196		}
197		
198		access(all)
199		view fun getSupportedNFTTypes():{ Type: Bool}{ 
200			panic("implement me")
201		}
202		
203		access(all)
204		view fun isSupportedNFTType(type: Type): Bool{ 
205			panic("implement me")
206		}
207		
208		access(all)
209		fun createEmptyCollection(): @{NonFungibleToken.Collection}{ 
210			return <-create Collection()
211		}
212		
213		init(){ 
214			self.ownedNFTs <-{} 
215		}
216	}
217	
218	access(all)
219	fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection}{ 
220		return <-create Collection()
221	}
222	
223	access(all)
224	resource Admin{ 
225		access(all)
226		fun mintInceptionBlackBox(recipient: &{NonFungibleToken.CollectionPublic}){ 
227			pre{ 
228				InceptionBlackBox.mintLimit >= InceptionBlackBox.totalSupply:
229					"InceptionBlackBox is out of stock"
230			}
231			let newNFT: @NFT <- create InceptionBlackBox.NFT(initID: InceptionBlackBox.totalSupply, serialNumber: InceptionBlackBox.totalSupply)
232			emit Minted(id: newNFT.id)
233			recipient.deposit(token: <-newNFT)
234			InceptionBlackBox.totalSupply = InceptionBlackBox.totalSupply + 1
235		}
236		
237		access(all)
238		fun updateInceptionBlackBoxMetadata(newMetadata:{ String: String}){ 
239			InceptionBlackBox.InceptionBlackBoxMetadata.updateMetadata(newMetadata: newMetadata)
240		}
241		
242		access(all)
243		fun updateInceptionBlackBoxCrystalPrice(newCrystalPrice: UInt64){ 
244			InceptionBlackBox.crystalPrice = newCrystalPrice
245		}
246		
247		access(all)
248		fun increaseMintLimit(increment: UInt64){ 
249			pre{ 
250				increment > 0:
251					"increment must be a positive number"
252			}
253			InceptionBlackBox.mintLimit = InceptionBlackBox.mintLimit + increment
254		}
255	}
256	
257	access(all)
258	fun getInceptionBlackBoxMetadata(): InceptionBlackBox.InceptionBlackBoxTemplate{ 
259		return InceptionBlackBox.InceptionBlackBoxMetadata
260	}
261
262  access(all) view fun getContractViews(resourceType: Type?): [Type] {
263		return []
264	}
265
266	access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
267		return nil
268	}
269	
270	init(){ 
271		self.CollectionStoragePath = /storage/InceptionBlackBoxCollection
272		self.CollectionPublicPath = /public/InceptionBlackBoxCollection
273		self.AdminStoragePath = /storage/InceptionBlackBoxAdmin
274		self.totalSupply = 1
275		self.crystalPrice = 18446744073709551615
276		self.mintLimit = 0
277		self.InceptionBlackBoxMetadata = InceptionBlackBoxTemplate(name: "Inception Black Box", description: "Raffle Box that contains good things", metadata:{} )
278		let admin <- create Admin()
279		self.account.storage.save(<-admin, to: self.AdminStoragePath)
280		emit ContractInitialized()
281	}
282}
283