TransactionSEALED
█%▓╳@■&◇#%○~■?▒╳░#■?*&▒░!#□▒╳╳??╲^^▒!■▒█*◇●▓?▫╱□░●!╲^○▒●●╱□◇◇◆!■
Transaction ID
Execution Fee
0.00000828 FLOWTransaction Summary
Contract CallCalled FlowToken, FungibleToken, MetadataViews +7 more
Script Arguments
0listingResourceIDUInt64
273778396297635
1storefrontAddressAddress
2commissionRecipientAddress?
Cadence Script
1import FlowToken from 0x1654653399040a61
2import FungibleToken from 0xf233dcee88fe0abe
3import MetadataViews from 0x1d7e57aa55817448
4import NonFungibleToken from 0x1d7e57aa55817448
5import NFTStorefrontV2 from 0x4eb8a10cb9f87357
6import HWGarageCard from 0xd0bcefdf1e67ea85
7import HWGaragePack from 0xd0bcefdf1e67ea85
8import HWGarageCardV2 from 0xd0bcefdf1e67ea85
9import HWGaragePackV2 from 0xd0bcefdf1e67ea85
10import HWGarageTokenV2 from 0xd0bcefdf1e67ea85
11
12transaction(listingResourceID: UInt64, storefrontAddress: Address, commissionRecipient: Address?) {
13 let paymentVault: @FungibleToken.Vault
14 let HWGarageCardV2Collection: &HWGarageCardV2.Collection{NonFungibleToken.Receiver}
15 let storefront: &NFTStorefrontV2.Storefront{NFTStorefrontV2.StorefrontPublic}
16 let listing: &NFTStorefrontV2.Listing{NFTStorefrontV2.ListingPublic}
17 var commissionRecipientCap: Capability<&{FungibleToken.Receiver}>?
18
19 prepare(acct: AuthAccount) {
20
21
22 if acct.borrow<&HWGarageCard.Collection>(from: HWGarageCard.CollectionStoragePath) == nil {
23 let collection <- HWGarageCard.createEmptyCollection()
24 acct.save(<-collection, to: HWGarageCard.CollectionStoragePath)
25 }
26 if acct.getCapability<&HWGarageCard.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageCard.HWGarageCardCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageCard.CollectionPublicPath).borrow() == nil {
27 acct.link<&HWGarageCard.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageCard.HWGarageCardCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageCard.CollectionPublicPath, target: HWGarageCard.CollectionStoragePath)
28 }
29
30 if acct.borrow<&HWGarageCardV2.Collection>(from: HWGarageCardV2.CollectionStoragePath) == nil {
31 let collection <- HWGarageCardV2.createEmptyCollection()
32 acct.save(<-collection, to: HWGarageCardV2.CollectionStoragePath)
33 }
34 if acct.getCapability<&HWGarageCardV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageCardV2.CardCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageCardV2.CollectionPublicPath).borrow() == nil {
35 acct.link<&HWGarageCardV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageCardV2.CardCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageCardV2.CollectionPublicPath, target: HWGarageCardV2.CollectionStoragePath)
36 }
37
38 if acct.borrow<&HWGaragePack.Collection>(from: HWGaragePack.CollectionStoragePath) == nil {
39 let collection <- HWGaragePack.createEmptyCollection()
40 acct.save(<-collection, to: HWGaragePack.CollectionStoragePath)
41 }
42 if acct.getCapability<&HWGaragePack.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGaragePack.PackCollectionPublic, MetadataViews.ResolverCollection}>(HWGaragePack.CollectionPublicPath).borrow() == nil {
43 acct.link<&HWGaragePack.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGaragePack.PackCollectionPublic, MetadataViews.ResolverCollection}>(HWGaragePack.CollectionPublicPath, target: HWGaragePack.CollectionStoragePath)
44 }
45
46 if acct.borrow<&HWGaragePackV2.Collection>(from: HWGaragePackV2.CollectionStoragePath) == nil {
47 let collection <- HWGaragePackV2.createEmptyCollection()
48 acct.save(<-collection, to: HWGaragePackV2.CollectionStoragePath)
49 }
50 if acct.getCapability<&HWGaragePackV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGaragePackV2.PackCollectionPublic, MetadataViews.ResolverCollection}>(HWGaragePackV2.CollectionPublicPath).borrow() == nil {
51 acct.link<&HWGaragePackV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGaragePackV2.PackCollectionPublic, MetadataViews.ResolverCollection}>(HWGaragePackV2.CollectionPublicPath, target: HWGaragePackV2.CollectionStoragePath)
52 }
53
54 if acct.borrow<&HWGarageTokenV2.Collection>(from: HWGarageTokenV2.CollectionStoragePath) == nil {
55 let collection <- HWGarageTokenV2.createEmptyCollection()
56 acct.save(<-collection, to: HWGarageTokenV2.CollectionStoragePath)
57 }
58 if acct.getCapability<&HWGarageTokenV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageTokenV2.TokenCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageTokenV2.CollectionPublicPath).borrow() == nil {
59 acct.link<&HWGarageTokenV2.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Receiver, HWGarageTokenV2.TokenCollectionPublic, MetadataViews.ResolverCollection}>(HWGarageTokenV2.CollectionPublicPath, target: HWGarageTokenV2.CollectionStoragePath)
60 }
61
62
63 if acct.borrow<&NFTStorefrontV2.Storefront>(from: NFTStorefrontV2.StorefrontStoragePath) == nil {
64 let collection <- NFTStorefrontV2.createStorefront() as! @NFTStorefrontV2.Storefront
65 acct.save(<-collection, to: NFTStorefrontV2.StorefrontStoragePath)
66 }
67 if acct.getCapability<&NFTStorefrontV2.Storefront{NFTStorefrontV2.StorefrontPublic}>(NFTStorefrontV2.StorefrontPublicPath).borrow() == nil {
68 acct.link<&NFTStorefrontV2.Storefront{NFTStorefrontV2.StorefrontPublic}>(NFTStorefrontV2.StorefrontPublicPath, target: NFTStorefrontV2.StorefrontStoragePath)
69 }
70
71 self.commissionRecipientCap = nil
72 // self.commissionRecipientCap = getAccount(commissionRecipient!).getCapability<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)
73 // Access the storefront public resource of the seller to purchase the listing.
74 self.storefront = getAccount(storefrontAddress)
75 .getCapability<&NFTStorefrontV2.Storefront{NFTStorefrontV2.StorefrontPublic}>(
76 NFTStorefrontV2.StorefrontPublicPath
77 )
78 .borrow()
79 ?? panic("Could not borrow Storefront from provided address")
80
81 // Borrow the listing
82 self.listing = self.storefront.borrowListing(listingResourceID: listingResourceID)
83 ?? panic("No Offer with that ID in Storefront")
84 let price = self.listing.getDetails().salePrice
85
86 // Access the vault of the buyer to pay the sale price of the listing.
87 let mainFlowVault = acct.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)
88 ?? panic("Cannot borrow FlowToken vault from acct storage")
89 self.paymentVault <- mainFlowVault.withdraw(amount: price)
90
91 // Access the buyer's NFT collection to store the purchased NFT.
92 self.HWGarageCardV2Collection = acct.borrow<&HWGarageCardV2.Collection{NonFungibleToken.Receiver}>(
93 from: HWGarageCardV2.CollectionStoragePath
94 ) ?? panic("Cannot borrow buyers Pack collection receiver")
95
96 // Fetch the commission amt.
97 let commissionAmount = self.listing.getDetails().commissionAmount
98
99 if commissionRecipient != nil && commissionAmount != 0.0 {
100 // Access the capability to receive the commission.
101 let _commissionRecipientCap = getAccount(commissionRecipient!).getCapability<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)
102 assert(_commissionRecipientCap.check(), message: "Commission Recipient doesn't have FT receiving capability")
103 self.commissionRecipientCap = _commissionRecipientCap
104 } else if commissionAmount == 0.0 {
105 self.commissionRecipientCap = nil
106 } else {
107 panic("Commission recipient can not be empty when commission amount is non zero")
108 }
109 }
110
111 execute {
112 // Purchase the NFT
113 let item <- self.listing.purchase(
114 payment: <-self.paymentVault,
115 commissionRecipient: self.commissionRecipientCap
116 )
117 // Deposit the NFT in the buyer's collection.
118 self.HWGarageCardV2Collection.deposit(token: <-item)
119 }
120}