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!
Open the starter code for this tutorial in the Flow Playground:
https://play.onflow.org/49ec2856-1258-4675-bac3-850b4bae1929
The tutorial will be asking you to take various actions to interact with this code.
The code in this tutorial and in the playground uses Cadence 0.42. The link will still work with the current version of the playground, but when the playground is updated to Cadence 1.0, the link will be replaced with a 1.0-compatible version. It is recommended that since Flow is so close to upgrading to Cadence 1.0, that you learn Cadence 1.0 features and syntax.
If you have already completed the Marketplace tutorial, please move on to Composable Resources: Kitty Hats.
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 inExampleToken.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 account0x02
. - 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 account0x01
as the only signer to set up account0x01
's storage.
- Run the transaction in Transaction 2. This is the
SetupAccount2Transaction.cdc
file. Use account0x02
as the only signer to set up account0x02
's storage.
- Run the transaction in Transaction 3. This is the
SetupAccount1TransactionMinting.cdc
file. Use account0x01
as the only signer to mint fungible tokens for account 1 and 2.
- Run the script
CheckSetupScript.cdc
file in Script 1 to ensure everything is set up.
- The script should not panic and you should see something like this output
_10"Account 1 Balance"_1040.00000000_10"Account 2 Balance"_1020.00000000_10"Account 1 NFTs"_10[1]_10"Account 2 NFTs"_10[]
With your playground now in the correct state, you're ready to continue with the next tutorial.
You do not need to open a new playground session for the marketplace tutorial. You can just continue using this one.