MarketplaceSEALED
▓■!%?▒@○▓▓!^█^^▪▫◇■?█▒~&╱╲▪&█□~▒?~%?□░^○□?╲█!~$▓●▪*&■▒%!░▫^%▫■~▪
Transaction ID
Execution Fee
0.0000255 FLOWPayer
Proposerseq:31 key:7
Authorizers
2Transaction Summary
Marketplace
Called FungibleToken, NonFungibleToken, DapperUtilityCoin +2 more
Script Arguments
0saleItemIDUInt64
53443
1saleItemPriceUFix64
11.00000000
2royaltyPercentUFix64
0.05000000
Cadence Script
1import FungibleToken from 0xf233dcee88fe0abe
2import NonFungibleToken from 0x1d7e57aa55817448
3import DapperUtilityCoin from 0xead892083b3e2c6c
4import MFLPlayer from 0x8ebcbfd516b1da27
5import NFTStorefront from 0x4eb8a10cb9f87357
6
7/**
8 This transaction can be used to place a Player NFT for sale on a marketplace such that a specified percentage of the proceeds of the sale
9 go to the dapp as a royalty.
10**/
11
12transaction(saleItemID: UInt64, saleItemPrice: UFix64, royaltyPercent: UFix64) {
13 let sellerPaymentReceiver: Capability<&{FungibleToken.Receiver}>
14 let nftProvider: Capability<&MFLPlayer.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>
15 let storefront: &NFTStorefront.Storefront
16 let dappAddress: Address
17
18 // It's important that the dapp account authorize this transaction so the dapp as the ability
19 // to validate and approve the royalty included in the sale.
20 prepare(dapp: AuthAccount, seller: AuthAccount) {
21 self.dappAddress = dapp.address
22
23 // If the account doesn't already have a storefront, create one and add it to the account
24 if seller.borrow<&NFTStorefront.Storefront>(from: NFTStorefront.StorefrontStoragePath) == nil {
25 let newstorefront <- NFTStorefront.createStorefront()
26 seller.save(<-newstorefront, to: NFTStorefront.StorefrontStoragePath)
27 seller.link<&NFTStorefront.Storefront{NFTStorefront.StorefrontPublic}>(
28 NFTStorefront.StorefrontPublicPath,
29 target: NFTStorefront.StorefrontStoragePath
30 )
31 }
32
33 // Get a reference to the receiver that will receive the fungible tokens if the sale executes.
34 self.sellerPaymentReceiver = seller.getCapability<&{FungibleToken.Receiver}>(/public/dapperUtilityCoinReceiver)
35 assert(self.sellerPaymentReceiver.borrow() != nil, message: "Missing or mis-typed DapperUtilityCoin receiver")
36
37 // If the user does not have their collection linked to their account, link it.
38 let nftProviderPrivatePath = /private/MFLPlayerCollectionProviderForNFTStorefront
39 let hasLinkedCollection = seller.getCapability<&MFLPlayer.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(nftProviderPrivatePath)!.check()
40 if !hasLinkedCollection {
41 seller.unlink(nftProviderPrivatePath)
42 seller.link<&MFLPlayer.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(
43 nftProviderPrivatePath,
44 target: MFLPlayer.CollectionStoragePath
45 )
46 }
47
48 // Get a capability to access the user's NFT collection.
49 self.nftProvider = seller.getCapability<&MFLPlayer.Collection{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(nftProviderPrivatePath)!
50 assert(self.nftProvider.borrow() != nil, message: "Missing or mis-typed collection provider")
51
52 // Get a reference to the user's NFT storefront
53 self.storefront = seller.borrow<&NFTStorefront.Storefront>(from: NFTStorefront.StorefrontStoragePath)
54 ?? panic("Missing or mis-typed NFTStorefront Storefront")
55
56 // Make sure this NFT is not already listed for sale in this storefront.
57 let existingOffers = self.storefront.getListingIDs()
58 if existingOffers.length > 0 {
59 for listingResourceID in existingOffers {
60 let listing: &NFTStorefront.Listing{NFTStorefront.ListingPublic}? = self.storefront.borrowListing(listingResourceID: listingResourceID)
61 if listing != nil && listing!.getDetails().nftID == saleItemID && listing!.getDetails().nftType == Type<@MFLPlayer.NFT>(){
62 self.storefront.removeListing(listingResourceID: listingResourceID)
63 }
64 }
65 }
66 }
67
68 // Make sure dapp is actually the dapp and not some random account
69 pre {
70 self.dappAddress == 0x15e71a9f7fe7d53d : "Requires valid authorizing signature"
71 }
72
73 execute {
74 // Calculate the amout the seller should receive if the sale executes, and the amount
75 // that should be sent to the dapp as a royalty.
76 let amountSeller = saleItemPrice * (1.0 - royaltyPercent)
77 let amountRoyalty = saleItemPrice - amountSeller
78
79 // Get the royalty recipient's public account object
80 let royaltyRecipient = getAccount(0x15e71a9f7fe7d53d)
81
82 // Get a reference to the royalty recipient's Receiver
83 let royaltyReceiverRef = royaltyRecipient.getCapability<&{FungibleToken.Receiver}>(/public/dapperUtilityCoinReceiver)
84 assert(royaltyReceiverRef.borrow() != nil, message: "Missing or mis-typed DapperUtilityCoin royalty receiver")
85
86 let saleCutSeller = NFTStorefront.SaleCut(
87 receiver: self.sellerPaymentReceiver,
88 amount: amountSeller
89 )
90
91 let saleCutRoyalty = NFTStorefront.SaleCut(
92 receiver: royaltyReceiverRef,
93 amount: amountRoyalty
94 )
95
96 self.storefront.createListing(
97 nftProviderCapability: self.nftProvider,
98 nftType: Type<@MFLPlayer.NFT>(),
99 nftID: saleItemID,
100 salePaymentVaultType: Type<@DapperUtilityCoin.Vault>(),
101 saleCuts: [saleCutSeller, saleCutRoyalty]
102 )
103 }
104}