-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorking NFT Transactions
More file actions
101 lines (72 loc) · 3.16 KB
/
Working NFT Transactions
File metadata and controls
101 lines (72 loc) · 3.16 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
// Create Collections
import FrostyMugverse from 0x01
import NonFungibleToken from 0x02
transaction () {
//beerName: String, beerStyle: String, abv: UFix64, ibu: UFix64
prepare(acct: AuthAccount) {
//add collection to user storage
acct.save(<- FrostyMugverse.createEmptyCollection(), to: /storage/MyCollection)
//create public link to collection from private account
acct.link<&FrostyMugverse.Collection{NonFungibleToken.CollectionPublic, FrostyMugverse.ICollectionPublic}>(/public/MyCollection, target: /storage/MyCollection)
}
execute {
log("Stored a Collection")
}
}
// Create / Store NFT's
import FrostyMugverse from 0x01
import NonFungibleToken from 0x02
transaction (recipient: Address, _beerName: String, _beerStyle: String, _abv: UFix64, _ibu: UFix64) {
//beerName: String, beerStyle: String, abv: UFix64, ibu: UFix64
//The NFT Minter will sign this transaction
prepare(acct: AuthAccount) {
let nftMinter = acct.borrow<&FrostyMugverse.Minter>(from: /storage/Minter) ?? panic("Could not get NFT Minter")
let publicRef = getAccount(recipient).getCapability(/public/MyCollection)
.borrow<&FrostyMugverse.Collection{FrostyMugverse.ICollectionPublic}>()
?? panic("This account does not have a collection.")
let baseNFT <- nftMinter.CreateNFT()
let beerOne <- nftMinter.CreateBeer(beername: _beerName, style: _beerStyle, abv: _abv, ibu: _ibu)
let oldBeer <- baseNFT.beerItems[_beerName] <- beerOne
log("Gave a Beer to a Frosty Muggin'!")
destroy oldBeer
log(baseNFT.beerItems.keys)
publicRef.deposit(token: <- baseNFT)
}
execute {
log("Deposite newly minted NFT into Collection")
}
}
// Transfer NFT's
import NFTTemplate from 0x01
import NonFungibleToken from 0x02
//where the NFT is going
transaction (recipient: Address, id: UInt64) {
//beerName: String, beerStyle: String, abv: UFix64, ibu: UFix64
//The account sending the NFT
prepare(acct: AuthAccount) {
//get sender collection
let collection = acct.borrow<&NFTTemplate.Collection>(from: /storage/MyCollection) ?? panic("Could Not Retreive Sender Collection")
//get receiver public collection info
let publicRef = getAccount(recipient).getCapability(/public/MyCollection)
.borrow<&NFTTemplate.Collection{NFTTemplate.ICollectionPublic}>()
?? panic("The receiving account does not have a collection.")
//deposit NFT
publicRef.deposit(token: <- collection.withdraw(withdrawID: id))
}
execute {
log("Transferred NFT into Collection")
}
}
//Read NFT
import FrostyMugverse from 0x01
import NonFungibleToken from 0x02
pub fun main(account: Address, id: UInt64): [UInt64] {
let publicRef = getAccount(account).getCapability(/public/MyCollection)
.borrow<&FrostyMugverse.Collection{FrostyMugverse.ICollectionPublic}>()
?? panic("Could not borrow NFT")
let ref = publicRef.borrowDetailedNFT(id: id)
log(ref.id)
log(ref.backgroundItems.keys)
log(ref.beerItems.keys)
return publicRef.getIDs()
}