Smart Contract

FlowverseSocks

A.ce4c02539d1fabe8.FlowverseSocks

Deployed

1w ago
Feb 16, 2026, 02:06:24 AM UTC

Dependents

56 imports
1import NonFungibleToken from 0x1d7e57aa55817448
2import ViewResolver from 0x1d7e57aa55817448
3import MetadataViews from 0x1d7e57aa55817448
4import FungibleToken from 0xf233dcee88fe0abe
5
6
7access(all) contract FlowverseSocks : NonFungibleToken {
8
9    access(all) var totalSupply: UInt64
10    access(all) var nextID: UInt64
11    access(all) let CollectionStoragePath: StoragePath
12    access(all) let CollectionPublicPath: PublicPath
13    access(all) let MinterStoragePath: StoragePath
14    access(all) let AdminStoragePath: StoragePath
15
16    //pub var CollectionPrivatePath: PrivatePath
17    access(all) event ContractInitialized()
18    access(all) event Withdraw(id: UInt64, from: Address?)
19    access(all) event Deposit(id: UInt64, to: Address?)
20    access(all) event Mint(id: UInt64, creator: Address, metadata: {String:String})
21    access(all) event Destroy(id: UInt64)
22    
23    access(all) var baseURI: String
24
25    access(all) fun getTokenURI(id: UInt64): String {
26        return self.baseURI.concat("/").concat(id.toString()) ;
27    }
28    
29    // We use dict to store raw metadata
30    access(all) resource interface RawMetadata {
31        access(all) fun getRawMetadata(): {String: String}
32    }
33
34    access(all) resource NFT: NonFungibleToken.NFT, RawMetadata {
35        access(all) let id: UInt64
36        access(all) let creator: Address
37        access(self) let metadata: {String:String}
38
39        init(
40            id: UInt64,
41            creator: Address,
42            metadata: {String: String}
43        ) {
44            self.id = id
45            self.creator = creator
46            self.metadata = metadata
47        }
48
49       access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
50        return <- create Collection()
51       }
52
53        access(all) view fun getViews(): [Type] {
54            return [
55                Type<MetadataViews.Display>(),
56                Type<MetadataViews.Medias>(),
57                Type<MetadataViews.Royalties>(),
58                Type<MetadataViews.ExternalURL>(),
59                Type<MetadataViews.NFTCollectionData>(),
60                Type<MetadataViews.NFTCollectionDisplay>()
61          ]
62        }
63
64        access(all) fun resolveView(_ view: Type): AnyStruct? {
65            switch view {
66                case Type<MetadataViews.Display>():
67                    return MetadataViews.Display(
68                        name: "Socks by Flowverse #".concat(self.id.toString()),
69                        description: "Socks by Flowverse are versatile NFTs that enable you to claim 1 limited edition pair of physical Flowverse Socks, shipped globally. Instructions on how to redeem will be published on the Flowverse website early 2022 and will involve a shipping + raw material cost. Each NFT can only be redeemed once for a physical pair of socks. Make sure to check if this specific pair has already been redeemed prior to purchase by checking the Flowverse website here: https://flowverse.co/socks . These NFTs are created by Designer and 3D motion artist Jenny Jiang. There are 111 total Socks by Flowverse. ",
70                        thumbnail: MetadataViews.HTTPFile(
71                            url: "https://chainbase.media.nft.matrixlabs.org/FlowverseSocks/default.gif"
72                        )
73                    )
74                case Type<MetadataViews.ExternalURL>():
75                    return MetadataViews.ExternalURL("https://www.socknft.com/")
76                case Type<MetadataViews.Royalties>():
77                    return MetadataViews.Royalties([MetadataViews.Royalty(
78                        receiver: getAccount(0x604b63bcbef5974f).capabilities.get<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)!,
79                        cut: 0.05,
80                        description: "Flowverse artist royalty"
81                    )])
82                case Type<MetadataViews.Medias>():
83                    return MetadataViews.Medias([MetadataViews.Media(file: MetadataViews.HTTPFile(url: "https://chainbase.media.nft.matrixlabs.org/FlowverseSocks/default_vedio.mp4"), mediaType: "video/mp4")])
84                case Type<MetadataViews.NFTCollectionDisplay>():
85                    let externalURL = MetadataViews.ExternalURL("https://www.socknft.com/")
86                    let squareImage = MetadataViews.Media(file: MetadataViews.HTTPFile(url: "https://media.nft.matrixmarket.xyz/media/dbbrUIkarYLXKKjiY5AYk_IMAGE.png"), mediaType: "image")
87                    let bannerImage = MetadataViews.Media(file: MetadataViews.HTTPFile(url: "https://media.nft.matrixmarket.xyz/media/cvR_VOmK5g6oGMhXRj1pR_IMAGE.png"), mediaType: "image")
88                    return MetadataViews.NFTCollectionDisplay(name: "Flowverse Socks", description: "Socks by Flowverse are versatile NFTs that enable you to claim 1 limited edition pair of physical Flowverse Socks, shipped globally. The total number of Socks by Flowverse is 111.", externalURL: externalURL, squareImage: squareImage, bannerImage: bannerImage, socials: { "discord": MetadataViews.ExternalURL("https://discord.com/invite/flowverse"), "twitter" : MetadataViews.ExternalURL("https://twitter.com/flowverse_")})
89              case Type<MetadataViews.NFTCollectionData>():
90                    return MetadataViews.NFTCollectionData(storagePath: FlowverseSocks.CollectionStoragePath,
91			          	publicPath: FlowverseSocks.CollectionPublicPath,
92                        publicCollection: Type<&FlowverseSocks.Collection>(),
93                        publicLinkedType: Type<&FlowverseSocks.Collection>(),
94                        createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
95                            return <-FlowverseSocks.createEmptyCollection(nftType: Type<@FlowverseSocks.NFT>())
96                        }))
97                }
98            return nil
99        }
100
101        access(all) fun getRawMetadata(): {String: String} {
102            return self.metadata
103        }
104
105    }
106
107    access(all) resource interface FlowverseSocksCollectionPublic {}
108
109    access(all) resource Collection: FlowverseSocksCollectionPublic, NonFungibleToken.Collection {
110        
111        access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
112
113        init () {
114            self.ownedNFTs <- {}
115        }
116
117        /// getSupportedNFTTypes returns a list of NFT types that this receiver accepts
118        access(all) view fun getSupportedNFTTypes(): {Type: Bool} {
119            let supportedTypes: {Type: Bool} = {}
120            supportedTypes[Type<@FlowverseSocks.NFT>()] = true
121            return supportedTypes
122        }
123
124        /// Returns whether or not the given type is accepted by the collection
125        /// A collection that can accept any type should just return true by default
126        access(all) view fun isSupportedNFTType(type: Type): Bool {
127            return type == Type<@FlowverseSocks.NFT>()
128        }
129
130        // withdraw removes an NFT from the collection and moves it to the caller
131        access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
132            let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT")
133
134            emit Withdraw(id: token.id, from: self.owner?.address)
135
136            return <-token
137        }
138
139        // deposit takes a NFT and adds it to the collections dictionary
140        // and adds the ID to the id array
141        access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
142            let token <- token as! @FlowverseSocks.NFT
143
144            let id: UInt64 = token.id
145
146            let oldToken <- self.ownedNFTs[id] <- token
147
148            emit Deposit(id: id, to: self.owner?.address)
149
150            destroy oldToken
151        }
152
153        // getIDs returns an array of the IDs that are in the collection
154        access(all) view fun getIDs(): [UInt64] {
155            return self.ownedNFTs.keys
156        }
157
158        access(all) view fun getLength(): Int {
159            return self.ownedNFTs.length
160        }
161
162        // borrowNFT gets a reference to an NFT in the collection
163        // so that the caller can read its metadata and call its methods
164        access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
165            return &self.ownedNFTs[id]
166        }
167
168        access(all) view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}? {
169            if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
170                return nft as &{ViewResolver.Resolver}
171            }
172            return nil
173        }
174
175        access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
176            return <- create Collection()
177        }
178
179    }
180
181    access(all) view fun getContractViews(resourceType: Type?): [Type] {
182        return [
183            Type<MetadataViews.NFTCollectionData>(),
184            Type<MetadataViews.NFTCollectionDisplay>()
185        ]
186    }
187
188    access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
189        switch viewType {
190            case Type<MetadataViews.NFTCollectionData>():
191                let collectionsData = MetadataViews.NFTCollectionData(
192                    storagePath: self.CollectionStoragePath,
193                    publicPath: self.CollectionPublicPath,
194                    publicCollection: Type<&FlowverseSocks.Collection>(),
195                    publicLinkedType: Type<&FlowverseSocks.Collection>(),
196                    createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
197                        return <-FlowverseSocks.createEmptyCollection(nftType: Type<@FlowverseSocks.NFT>())
198                    })
199                )
200                return collectionsData
201            case Type<MetadataViews.NFTCollectionDisplay>():
202                let squareMedia= MetadataViews.Media(
203                    file: MetadataViews.HTTPFile(
204                        url: "https://media.nft.matrixmarket.xyz/media/dbbrUIkarYLXKKjiY5AYk_IMAGE.png"
205                    ),
206                    mediaType: "image/png"
207                )
208                let bannerMedia= MetadataViews.Media(
209                    file: MetadataViews.HTTPFile(
210                        url: "https://media.nft.matrixmarket.xyz/media/cvR_VOmK5g6oGMhXRj1pR_IMAGE.png"
211                    ),
212                    mediaType: "image/png"
213                )
214                return MetadataViews.NFTCollectionDisplay(
215                    name: "Flowverse Socks",
216                    description: "Socks by Flowverse are versatile NFTs that enable you to claim 1 limited edition pair of physical Flowverse Socks, shipped globally. The total number of Socks by Flowverse is 111.",
217                    externalURL: MetadataViews.ExternalURL("https://www.socknft.com/"),
218                    squareImage: squareMedia,
219                    bannerImage: bannerMedia,
220                    socials: {
221                        "twitter": MetadataViews.ExternalURL("https://twitter.com/flowverse_")
222                    }
223                )
224            default:
225                return nil
226        }
227    }
228
229    access(all) fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection} {
230        return <- create Collection()
231    }
232
233    // Resource that an admin or something similar would own to be
234    // able to mint new NFTs
235    //
236    access(all) resource NFTMinter {
237
238        // mintNFTWithID mints a new NFT with id
239        // and deposit it in the recipients collection using their collection reference
240        access(all) fun mintNFTWithID(
241            id: UInt64,
242            recipient: &{NonFungibleToken.CollectionPublic},
243            metadata: {String: String}
244        ){
245
246            if(FlowverseSocks.nextID <= id){
247                FlowverseSocks.nextID = id + 1
248            }
249            let creator = self.owner!.address
250            // create a new NFT
251            var newNFT <- create NFT(
252                id: id,
253                creator: creator,
254                metadata: metadata
255            )
256            emit Mint(id: newNFT.id, creator: creator, metadata: metadata)
257
258            // deposit it in the recipient's account using their reference
259            recipient.deposit(token: <-newNFT)
260
261            FlowverseSocks.totalSupply = FlowverseSocks.totalSupply + 1
262
263        }
264        // mintNFT mints a new NFT with a new ID
265        // and deposit it in the recipients collection using their collection reference
266        access(all) fun mintNFT(
267            recipient: &{NonFungibleToken.CollectionPublic},
268            metadata: {String: String}
269        ) {
270
271            let creator = self.owner!.address
272            // create a new NFT
273            var newNFT <- create NFT(
274                id: FlowverseSocks.nextID,
275                creator: creator,
276                metadata: metadata
277            )
278            emit Mint(id: newNFT.id, creator: creator, metadata: metadata)
279            FlowverseSocks.nextID = FlowverseSocks.nextID + 1
280
281            // deposit it in the recipient's account using their reference
282            recipient.deposit(token: <-newNFT)
283
284            FlowverseSocks.totalSupply = FlowverseSocks.totalSupply + 1
285
286        }
287    }
288    
289    access(all) resource Admin {
290        access(all) fun setBaseURI(
291            baseURI: String
292        ){
293            FlowverseSocks.baseURI = baseURI
294        }
295    }
296
297    init() {
298        // Initialize the total supply
299        self.totalSupply = 0
300        self.nextID = 0
301
302        // Set the named paths
303        self.CollectionStoragePath = /storage/MatrixMarketFlowverseSocksCollection
304        self.CollectionPublicPath = /public/MatrixMarketFlowverseSocksCollection
305        self.MinterStoragePath = /storage/MatrixMarketFlowverseSocksMinter
306        self.AdminStoragePath = /storage/MatrixMarketFlowverseSocksAdmin
307        
308        self.baseURI = ""
309        // Create a Collection resource and save it to storage
310        let collection <- create Collection()
311        self.account.storage.save(<-collection, to: self.CollectionStoragePath)
312
313        // Create a Minter resource and save it to storage
314        let minter <- create NFTMinter()
315        self.account.storage.save(<-minter, to: self.MinterStoragePath)
316
317        let admin <- create Admin()
318        self.account.storage.save(<-admin, to: self.AdminStoragePath)
319        
320        emit ContractInitialized()
321    }
322}
323
324