Smart Contract

UniversalCollection

A.befbaccb5032a457.UniversalCollection

Deployed

2h ago
Feb 28, 2026, 09:42:23 PM UTC

Dependents

0 imports
1import NonFungibleToken from 0x1d7e57aa55817448
2import MetadataViews from 0x1d7e57aa55817448
3import BaseCollection from 0xbefbaccb5032a457
4
5access(all) contract UniversalCollection {
6    access(all) resource Collection: BaseCollection.Collection {
7        access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
8        access(all) var nftType: Type
9
10        access(all) let data: {String: AnyStruct}
11        access(all) let resources: @{String: AnyResource}
12
13        access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
14            return <- create Collection(nftType: self.nftType)
15        }
16
17        access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
18            pre {
19                token.getType() == self.nftType: "unexpected nft type being deposited"
20            }
21
22            destroy self.ownedNFTs.insert(key: token.id, <-token)
23        }
24
25        access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
26            return &self.ownedNFTs[id]
27        }
28
29        access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
30            return <- self.ownedNFTs.remove(key: withdrawID)!
31        }
32
33        init (nftType: Type) {
34            self.ownedNFTs <- {}
35            self.nftType = nftType
36
37            self.data = {}
38            self.resources <- {}
39        }
40    }
41
42    access(all) fun createCollection(nftType: Type): @Collection {
43        return <- create Collection(nftType: nftType)
44    }
45}