Smart Contract

Helmet

A.f887ece39166906e.Helmet

Deployed

1d ago
Feb 26, 2026, 09:44:38 PM UTC

Dependents

0 imports
1import NonFungibleToken from 0x1d7e57aa55817448
2import MetadataViews from 0x1d7e57aa55817448
3import ViewResolver from 0x1d7e57aa55817448
4
5access(all) contract Helmet: NonFungibleToken {
6
7    access(all) let CollectionStoragePath: StoragePath
8    access(all) let CollectionPublicPath: PublicPath
9    access(all) let AdminStoragePath: StoragePath
10
11    access(all) var totalSupply: UInt64
12
13    access(all) struct HelmetMetadata {
14        access(all) let id: UInt64
15        access(all) let name: String
16        access(all) let description: String
17        access(all) let ipfsLink: String
18
19        init(id: UInt64, name: String, description: String, ipfsLink: String) {
20            self.id = id
21            self.name=name
22            self.description = description
23            self.ipfsLink=ipfsLink
24        }
25    }
26
27    access(all) resource NFT: NonFungibleToken.NFT {
28        access(all) let id: UInt64
29        access(all) let name: String
30        access(all) let description: String
31        access(all) let ipfsLink: String
32
33        init(initID: UInt64, name: String, description: String, ipfsLink: String) {
34            self.id = initID
35            self.name = name
36            self.description = description
37            self.ipfsLink = ipfsLink
38        }
39
40        access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
41            return <- Helmet.createEmptyCollection(nftType: Type<@NFT>())
42        }
43
44        access(all) view fun getViews(): [Type] {
45            return [
46                Type<MetadataViews.Display>(),
47                Type<MetadataViews.ExternalURL>(),
48                Type<MetadataViews.NFTCollectionData>(),
49                Type<MetadataViews.NFTCollectionDisplay>(),
50                Type<Helmet.HelmetMetadata>(),
51                Type<MetadataViews.Royalties>()
52            ]
53        }
54
55        access(all) fun resolveView(_ view: Type): AnyStruct? {
56            switch view {
57                case Type<MetadataViews.Display>():
58                    return MetadataViews.Display(
59                        name: self.name,
60                        description: self.description,
61                        thumbnail: MetadataViews.IPFSFile(
62                            cid: self.ipfsLink,
63                            path: nil
64                        )
65                    )
66                case Type<MetadataViews.ExternalURL>():
67                    return MetadataViews.ExternalURL("https://driverz.world/")
68                case Type<MetadataViews.NFTCollectionData>():
69                    return Helmet.resolveContractView(resourceType: Type<@NFT>(), viewType: Type<MetadataViews.NFTCollectionData>())
70                case Type<MetadataViews.NFTCollectionDisplay>():
71                    return Helmet.resolveContractView(resourceType: Type<@NFT>(), viewType: Type<MetadataViews.NFTCollectionDisplay>())
72                case Type<Helmet.HelmetMetadata>():
73                    return Helmet.HelmetMetadata(
74                        id: self.id,
75                        name: self.name,
76                        description: self.description,
77                        ipfsLink: self.ipfsLink
78                    )
79                case Type<MetadataViews.Royalties>():
80                    return MetadataViews.Royalties([])
81            }
82            return nil
83        }
84    }
85
86    access(all) resource interface CollectionPublic {
87        access(all) fun deposit(token: @{NonFungibleToken.NFT})
88        access(all) view fun getIDs(): [UInt64]
89        access(all) fun borrowArt(id: UInt64): &Helmet.NFT? {
90            // If the result isn't nil, the id of the returned reference
91            // should be the same as the argument to the function
92            post {
93                (result == nil) || (result?.id == id): 
94                    "Cannot borrow Moment reference: The ID of the returned reference is incorrect"
95            }
96        }
97    }
98
99    access(all) resource Collection: CollectionPublic, NonFungibleToken.Collection {
100        access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
101
102        access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
103            let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT")
104            return <-token
105        }
106
107        access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
108            let token <- token as! @Helmet.NFT
109            let id: UInt64 = token.id
110            let oldToken <- self.ownedNFTs[id] <- token
111            destroy oldToken
112        }
113
114        access(all) view fun getSupportedNFTTypes(): {Type: Bool} {
115            let supportedTypes: {Type: Bool} = {}
116            supportedTypes[Type<@NFT>()] = true
117            return supportedTypes
118        }
119
120        access(all) view fun isSupportedNFTType(type: Type): Bool {
121            return type == Type<@NFT>()
122        }
123
124        access(all) view fun getIDs(): [UInt64] {
125            return self.ownedNFTs.keys
126        }
127
128        access(all) view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}? {
129            if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
130                return nft as &{ViewResolver.Resolver}
131            }
132            return nil
133        }
134
135        access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
136            return (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)
137        }
138
139        access(all) fun borrowArt(id: UInt64): &Helmet.NFT? {
140            if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
141                return nft as! &NFT
142            }
143            return nil
144        }
145
146        access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
147            return <- Helmet.createEmptyCollection(nftType: Type<@NFT>())
148        }
149
150        init () {
151            self.ownedNFTs <- {}
152        }
153    }
154
155    access(all) fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection} {
156        return <- create Collection()
157    }
158
159	access(all) resource Admin {
160		access(all) fun mintNFT(
161		recipient: &{NonFungibleToken.CollectionPublic},
162		name: String,
163        description: String,
164        ipfsLink: String) {
165			recipient.deposit(token: <- create Helmet.NFT(
166			    initID: Helmet.totalSupply,
167                name: name,
168                description: description,
169			    ipfsLink: ipfsLink)
170            )
171
172            Helmet.totalSupply = Helmet.totalSupply + 1
173		}
174	}
175
176    access(all) view fun getContractViews(resourceType: Type?): [Type] {
177        return [
178            Type<MetadataViews.NFTCollectionData>(),
179            Type<MetadataViews.NFTCollectionDisplay>()
180        ]
181    }
182
183    access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
184        switch viewType {
185            case Type<MetadataViews.NFTCollectionData>():
186                let collectionData = MetadataViews.NFTCollectionData(
187                    storagePath: self.CollectionStoragePath,
188                    publicPath: self.CollectionPublicPath,
189                    publicCollection: Type<&Collection>(),
190                    publicLinkedType: Type<&Collection>(),
191                    createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
192                        return <- Helmet.createEmptyCollection(nftType: Type<@NFT>())
193                    })
194                )
195                return collectionData
196            case Type<MetadataViews.NFTCollectionDisplay>():
197                let squareMedia = MetadataViews.Media(
198                    file: MetadataViews.HTTPFile(
199                        url: "https://driverz.world/DriverzNFT-logo.png"
200                    ),
201                    mediaType: "image"
202                )
203                let bannerMedia = MetadataViews.Media(
204                    file: MetadataViews.HTTPFile(
205                        url: "https://driverz.world/DriverzNFT-logo.png"
206                    ),
207                    mediaType: "image"
208                )
209                return MetadataViews.NFTCollectionDisplay(
210                    name: "Driverz Utility Helmet",
211                    description: "Driverz Helmet Collection",
212                    externalURL: MetadataViews.ExternalURL("https://driverz.world/"),
213                    squareImage: squareMedia,
214                    bannerImage: bannerMedia,
215                    socials: {
216                        "twitter": MetadataViews.ExternalURL("https://twitter.com/DriverzWorld"),
217                        "discord": MetadataViews.ExternalURL("https://discord.gg/driverz"),
218                        "instagram": MetadataViews.ExternalURL("https://www.instagram.com/driverzworld")
219                    }
220                )
221        }
222        return nil
223    }
224
225    init() {
226        self.CollectionStoragePath = /storage/HelmetCollection
227        self.CollectionPublicPath = /public/HelmetCollection
228        self.AdminStoragePath = /storage/HelmetMinter
229
230        self.totalSupply = 0
231
232        let minter <- create Admin()
233        self.account.storage.save(<-minter, to: self.AdminStoragePath)
234
235        let collection <- create Collection()
236        self.account.storage.save(<-collection, to: Helmet.CollectionStoragePath)
237        let collectionCap = self.account.capabilities.storage.issue<&Collection>(self.CollectionStoragePath)
238        self.account.capabilities.publish(collectionCap, at: self.CollectionPublicPath)
239    }
240}