This is unreleased documentation for Flow Developer Portal Next version.
For up-to-date documentation, see the latest version (Current).
Version: Next
7. Marketplace Setup
In this tutorial, we're going to create a marketplace that uses both the fungible
and non-fungible token (NFTs) contracts that we have learned about in previous tutorials.
This page requires you to execute a series of transactions to setup your accounts to complete the Marketplace tutorial.
The next page contains the main content of the tutorial.
When you are done with the tutorial, check out the NFTStorefront repo
for an example of a production ready marketplace that you can use right now on testnet or mainnet!
tip
Open the starter code for this tutorial in the Flow Playground:
This guide will help you quickly get the playground to the state you need to complete the Marketplace tutorial.
The marketplace tutorial uses the Fungible Token and Non-Fungible token contracts
to allow users to buy and sell NFTs with fungible tokens.
The state of the accounts is the same as if you had completed the Fungible Token
and Non-Fungible Token tutorials in the same playground session.
Having your playground in this state is necessary to follow the Composable Smart Contracts: Marketplace tutorial.
Open account 0x01. Make sure the Fungible Token definitions in ExampleToken.cdc from the fungible token tutorial are in this account.
Deploy the ExampleToken code to account 0x01.
Switch to the ExampleNFT contract (Contract 2)
Make sure you have the NFT definitions in ExampleNFT.cdc from the Non-fungible token tutorial in account 0x02.
Deploy the NFT code to account 0x02 by selecting it as the deploying signer.
Run the transaction in Transaction 1. This is the SetupAccount1Transaction.cdc file.
Use account 0x01 as the only signer to set up account 0x01's storage.
SetupAccount1Transaction.cdc
_24
// SetupAccount1Transaction.cdc
_24
_24
import ExampleToken from 0x01
_24
import ExampleNFT from 0x02
_24
_24
// This transaction sets up account 0x01 for the marketplace tutorial
_24
// by publishing a Vault reference and creating an empty NFT Collection.
_24
transaction {
_24
prepare(acct: AuthAccount) {
_24
// Create a public Receiver capability to the Vault
log("Created a new empty collection and published a reference")
_24
}
_24
}
Run the transaction in Transaction 2. This is the SetupAccount2Transaction.cdc file.
Use account 0x02 as the only signer to set up account 0x02's storage.
SetupAccount2Transaction.cdc
_45
// SetupAccount2Transaction.cdc
_45
_45
import ExampleToken from 0x01
_45
import ExampleNFT from 0x02
_45
_45
// This transaction adds an empty Vault to account 0x02
_45
// and mints an NFT with id=1 that is deposited into
_45
// the NFT collection on account 0x01.
_45
transaction {
_45
_45
// Private reference to this account's minter resource
_45
let minterRef: &ExampleNFT.NFTMinter
_45
_45
prepare(acct: AuthAccount) {
_45
// create a new vault instance with an initial balance of 30
_45
let vaultA <- ExampleToken.createEmptyVault()
_45
_45
// Store the vault in the account storage
_45
acct.save<@ExampleToken.Vault>(<-vaultA, to: /storage/CadenceFungibleTokenTutorialVault)
_45
_45
// Create a public Receiver capability to the Vault
_45
let ReceiverRef = acct.link<&ExampleToken.Vault{ExampleToken.Receiver, ExampleToken.Balance}>(/public/CadenceFungibleTokenTutorialReceiver, target: /storage/CadenceFungibleTokenTutorialVault)
_45
_45
log("Created a Vault and published a reference")
_45
_45
// Borrow a reference for the NFTMinter in storage
Run the transaction in Transaction 3. This is the SetupAccount1TransactionMinting.cdc file.
Use account 0x01 as the only signer to mint fungible tokens for account 1 and 2.
SetupAccount1TransactionMinting.cdc
_37
// SetupAccount1TransactionMinting.cdc
_37
_37
import ExampleToken from 0x01
_37
import ExampleNFT from 0x02
_37
_37
// This transaction mints tokens for both accounts using
_37
// the minter stored on account 0x01.
_37
transaction {
_37
_37
// Public Vault Receiver References for both accounts
_37
let acct1Capability: Capability<&AnyResource{ExampleToken.Receiver}>
_37
let acct2Capability: Capability<&AnyResource{ExampleToken.Receiver}>
_37
_37
// Private minter references for this account to mint tokens
_37
let minterRef: &ExampleToken.VaultMinter
_37
_37
prepare(acct: AuthAccount) {
_37
// Get the public object for account 0x02
_37
let account2 = getAccount(0x02)
_37
_37
// Retrieve public Vault Receiver references for both accounts