Smart Contract

SimpleFlunksV2

A.bfffec679fff3a94.SimpleFlunksV2

Deployed

1w ago
Feb 19, 2026, 03:36:30 AM UTC

Dependents

1 imports
1import NonFungibleToken from 0x1d7e57aa55817448
2import MetadataViews from 0x1d7e57aa55817448
3import ViewResolver from 0x1d7e57aa55817448
4
5access(all)
6contract SimpleFlunksV2: NonFungibleToken {
7    
8    access(all) event ContractInitialized()
9    access(all) event Withdraw(id: UInt64, from: Address?)
10    access(all) event Deposit(id: UInt64, to: Address?)
11    access(all) event Minted(id: UInt64, to: Address?)
12    
13    access(all) var totalSupply: UInt64
14    
15    access(all) let CollectionStoragePath: StoragePath
16    access(all) let CollectionPublicPath: PublicPath
17    access(all) let AdminStoragePath: StoragePath
18    
19    access(all) resource NFT: NonFungibleToken.NFT, ViewResolver.Resolver {
20        
21        access(all) let id: UInt64
22        access(all) let name: String
23        access(all) let description: String
24        access(all) let image: String
25        
26        init(id: UInt64, name: String, description: String, image: String) {
27            self.id = id
28            self.name = name
29            self.description = description
30            self.image = image
31        }
32        
33        access(all) view fun getViews(): [Type] {
34            return [
35                Type<MetadataViews.Display>(),
36                Type<MetadataViews.NFTCollectionData>(),
37                Type<MetadataViews.NFTCollectionDisplay>(),
38                Type<MetadataViews.Royalties>(),
39                Type<MetadataViews.ExternalURL>(),
40                Type<MetadataViews.Serial>()
41            ]
42        }
43        
44        access(all) fun resolveView(_ view: Type): AnyStruct? {
45            switch view {
46                case Type<MetadataViews.Display>():
47                    return MetadataViews.Display(
48                        name: self.name,
49                        description: self.description,
50                        thumbnail: MetadataViews.HTTPFile(url: self.image)
51                    )
52                
53                case Type<MetadataViews.NFTCollectionData>():
54                    return SimpleFlunksV2.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>())
55                
56                case Type<MetadataViews.NFTCollectionDisplay>():
57                    return SimpleFlunksV2.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionDisplay>())
58                
59                case Type<MetadataViews.Royalties>():
60                    return MetadataViews.Royalties([])
61                
62                case Type<MetadataViews.ExternalURL>():
63                    return MetadataViews.ExternalURL("https://flunks.community")
64                
65                case Type<MetadataViews.Serial>():
66                    return MetadataViews.Serial(self.id)
67            }
68            return nil
69        }
70        
71        access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
72            return <-create Collection()
73        }
74    }
75    
76    access(all) resource Collection: NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.Collection, NonFungibleToken.CollectionPublic, ViewResolver.ResolverCollection {
77        
78        access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
79        
80        init() {
81            self.ownedNFTs <- {}
82        }
83        
84        access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
85            let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT")
86            emit Withdraw(id: token.id, from: self.owner?.address)
87            return <-token
88        }
89        
90        access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
91            let token <- token as! @SimpleFlunksV2.NFT
92            let id: UInt64 = token.id
93            let oldToken <- self.ownedNFTs[id] <- token
94            emit Deposit(id: id, to: self.owner?.address)
95            destroy oldToken
96        }
97        
98        access(all) view fun getIDs(): [UInt64] {
99            return self.ownedNFTs.keys
100        }
101        
102        access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
103            return &self.ownedNFTs[id]
104        }
105        
106        access(all) view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}? {
107            if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
108                return nft as &{ViewResolver.Resolver}
109            }
110            return nil
111        }
112        
113        access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
114            return <-create Collection()
115        }
116        
117        access(all) view fun getSupportedNFTTypes(): {Type: Bool} {
118            return {Type<@SimpleFlunksV2.NFT>(): true}
119        }
120        
121        access(all) view fun isSupportedNFTType(type: Type): Bool {
122            return type == Type<@SimpleFlunksV2.NFT>()
123        }
124    }
125    
126    access(all) resource Admin {
127        
128        access(all) fun mintNFT(
129            recipient: &{NonFungibleToken.CollectionPublic},
130            name: String,
131            description: String,
132            image: String
133        ) {
134            let newNFT <- create NFT(
135                id: SimpleFlunksV2.totalSupply,
136                name: name,
137                description: description,
138                image: image
139            )
140            
141            let recipientAddress = recipient.owner!.address
142            
143            recipient.deposit(token: <-newNFT)
144            
145            emit Minted(id: SimpleFlunksV2.totalSupply, to: recipientAddress)
146            
147            SimpleFlunksV2.totalSupply = SimpleFlunksV2.totalSupply + 1
148        }
149    }
150    
151    access(all) fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection} {
152        return <-create Collection()
153    }
154    
155    access(all) view fun getContractViews(resourceType: Type?): [Type] {
156        return [
157            Type<MetadataViews.NFTCollectionData>(),
158            Type<MetadataViews.NFTCollectionDisplay>()
159        ]
160    }
161    
162    access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
163        switch viewType {
164            case Type<MetadataViews.NFTCollectionData>():
165                return MetadataViews.NFTCollectionData(
166                    storagePath: SimpleFlunksV2.CollectionStoragePath,
167                    publicPath: SimpleFlunksV2.CollectionPublicPath,
168                    publicCollection: Type<&SimpleFlunksV2.Collection>(),
169                    publicLinkedType: Type<&SimpleFlunksV2.Collection>(),
170                    createEmptyCollectionFunction: (fun (): @{NonFungibleToken.Collection} {
171                        return <-SimpleFlunksV2.createEmptyCollection(nftType: Type<@SimpleFlunksV2.NFT>())
172                    })
173                )
174            
175            case Type<MetadataViews.NFTCollectionDisplay>():
176                return MetadataViews.NFTCollectionDisplay(
177                    name: "Flunks Community",
178                    description: "The official Flunks NFT collection on Flow mainnet",
179                    externalURL: MetadataViews.ExternalURL("https://flunks.community"),
180                    squareImage: MetadataViews.Media(
181                        file: MetadataViews.HTTPFile(url: "https://storage.googleapis.com/flunks_public/backpack/1c023bb17a570b7e114e35d195035e41fc60a5c3c60933daf1c780f51abfe24d.png"),
182                        mediaType: "image/png"
183                    ),
184                    bannerImage: MetadataViews.Media(
185                        file: MetadataViews.HTTPFile(url: "https://storage.googleapis.com/flunks_public/backpack/1c023bb17a570b7e114e35d195035e41fc60a5c3c60933daf1c780f51abfe24d.png"),
186                        mediaType: "image/png"
187                    ),
188                    socials: {
189                        "website": MetadataViews.ExternalURL("https://flunks.community")
190                    }
191                )
192        }
193        return nil
194    }
195    
196    init() {
197        self.totalSupply = 0
198        
199        self.CollectionStoragePath = /storage/SimpleFlunksV2Collection
200        self.CollectionPublicPath = /public/SimpleFlunksV2Collection
201        self.AdminStoragePath = /storage/SimpleFlunksV2Admin
202        
203        let admin <- create Admin()
204        self.account.storage.save(<-admin, to: self.AdminStoragePath)
205        
206        emit ContractInitialized()
207    }
208}
209