Marketplace
In this tutorial, you'll learn the basics of an NFT marketplace contract where you can buy and sell non-fungible tokens for $NEAR. In the previous tutorials, you went through and created a fully fledged NFT contract that incorporates all the standards found in the NFT standard.
Introduction
Throughout this tutorial, you'll learn how a marketplace contract could work on NEAR. This is meant to be an example and there is no canonical implementation. Feel free to branch off and modify this contract to meet your specific needs.
Using the same repository as the previous tutorials, if you checkout the 8.marketplace branch, you should have the necessary files to complete the tutorial.
git checkout 8.marketplace
File structure
market-contract
└── src
├── internal.ts
├── index.ts
├── nft_callbacks.ts
├── sale.ts
└── sale_views.ts
Usually, when doing work on multiple smart contracts that all pertain to the same repository, it's a good idea to structure them in their own folders as done in this tutorial. To make your work easier when building the smart contracts, we've also modified the repository's package.json file so that building both smart contracts can be easily done by running the following command.
yarn build
This will install the dependencies for both contracts and compile them to wasm files that are stored in the following directory.
nft-tutorial-js
└── build
├── nft.wasm
└── market.wasm
Understanding the contract
At first, the contract can be quite overwhelming but if you strip away all the fluff and dig into the core functionalities, it's actually quite simple. This contract was designed for only one thing - to allow people to buy and sell NFTs for NEAR. This includes the support for paying royalties, updating the price of your sales, removing sales and paying for storage.
Let's go through the files and take note of some of the important functions and what they do.