Cadence Cookbook

Contribute

Create a Marketplace

Create a Marketplace

14 Oct 2022

Contributed by Flow Blockchain

Intermediate

Create a secondary marketplace for your NFTS using the NFT Storefront Contract.

Smart Contract Example

The NFT Storefront contract enables users to list their NFTs for sale on a marketplace, purchase NFTs from others, borrow listings, and perform various other operations related to managing and interacting with the Storefront. To use these features, a user must first create a Storefront resource from the NFT Storefront contract and save it to their account. This Storefront resource acts as a gateway to functionalities such as creating and removing listings, retrieving and borrowing listings, cleaning up outdated listings, and even destroying the Storefront itself when no longer needed.

The createStorefront function facilitates this process, allowing anyone to easily create and save a Storefront resource to their account, unlocking full access to the Storefront’s capabilities.

Transaction Example
1 2 3 4 5 6 7 8 9 10 11 12 13 import "NFTStorefrontV2" // This transaction sets up the emulator account for the marketplace tutorial // by publishing a Vault reference and creating an empty NFT Collection. transaction { prepare(acct: auth(Storage) &Account) { // Save the newly created storefront resource into account storage acct.storage.save(<-NFTStorefrontV2.createStorefront(), to: NFTStorefrontV2.StorefrontStoragePath) log("Storefront created") } }

This transaction demonstrates how to set up a user account to participate in the marketplace by creating and saving a Storefront resource using the NFTStorefront contract. The createStorefront function is called to generate a new Storefront resource, which is then stored in the account's storage at the predefined NFTStorefront.StorefrontStoragePath.


ProgressNFT Storefront Essentials

Up Next: Create an NFT Listing

33%


Related Recipes

14 Oct 2022
Create an NFT Listing
Intermediate
01 Apr 2022
Purchase NFT on Marketplace
Intermediate