-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorking NFT Contract Template - Meets Flow NFT Standards
More file actions
108 lines (82 loc) · 3.07 KB
/
Copy pathWorking NFT Contract Template - Meets Flow NFT Standards
File metadata and controls
108 lines (82 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import NonFungibleToken from 0x02
access(all) contract NFTTemplate : NonFungibleToken {
//Constants
pub let maxSupply : UInt64
//Public
pub var totalSupply: UInt64
pub event ContractInitialized()
pub event Withdraw(id: UInt64, from: Address?)
pub event Deposit(id: UInt64, to: Address?)
//Private
//Resources
pub resource NFT : NonFungibleToken.INFT {
pub let id: UInt64
pub var beername: String
pub var style: String
pub var abv: UFix64
pub var ibu: UFix64
init(_beername: String, _style: String, _abv: UFix64, _ibu: UFix64){
self.id = NFTTemplate.totalSupply
self.beername = _beername
self.style = _style
self.abv = _abv
self.ibu = _ibu
NFTTemplate.totalSupply = NFTTemplate.totalSupply + 1
}
}
pub resource Minter {
pub fun CreateNFT(beername: String, style: String, abv: UFix64, ibu: UFix64): @NFT {
return <- create NFT(_beername: beername,_style: style, _abv: abv, _ibu: ibu)
}
init(){
}
}
pub resource Collection: NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic, ICollectionPublic {
pub var ownedNFTs: @{UInt64 : NonFungibleToken.NFT}
pub fun deposit(token: @NonFungibleToken.NFT){
//ensure it is an NFT of our type and not a Bored Ape
let depositToken <- token as! @NFT
//deposit nft into collection
emit Deposit(id: depositToken.id, to: self.owner?.address)
self.ownedNFTs[depositToken.id] <-! depositToken
}
pub fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT {
let token <- self.ownedNFTs.remove(key: withdrawID)
?? panic("Could Not Retreive NFT")
emit Withdraw(id: withdrawID, from: self.owner?.address)
return <- token
}
pub fun getIDs(): [UInt64] {
return self.ownedNFTs.keys
}
pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT {
return &self.ownedNFTs[id] as &NonFungibleToken.NFT
}
pub fun borrowDetailedNFT(id: UInt64): &NFT {
let refNFT = &self.ownedNFTs[id] as auth &NonFungibleToken.NFT
return refNFT as! &NFT
}
init(){
self.ownedNFTs <- {}
}
destroy(){
destroy self.ownedNFTs
}
}
pub resource interface ICollectionPublic{
pub fun getIDs() : [UInt64]
pub fun deposit(token: @NonFungibleToken.NFT)
pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT
pub fun borrowDetailedNFT(id: UInt64): &NFT
}
pub fun createEmptyCollection(): @Collection {
return <- create Collection()
}
// The init() function is required if the contract contains any fields.
init() {
emit ContractInitialized()
self.maxSupply = 10
self.totalSupply = 0
self.account.save(<- create Minter(), to: /storage/Minter)
}
}