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 as there is no canonical implementation. Feel free to branch off and modify this contract to meet your specific needs.
cd market-contract/
This folder contains both the actual contract code and dependencies as outlined below.
market-contract
├── Cargo.lock
├── Cargo.toml
├── README.md
└── src
├── external.rs
├── internal.rs
├── lib.rs
├── nft_callbacks.rs
├── sale.rs
└── sale_views.rs
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.
lib.rs
This file outlines what information is stored on the contract as well as some other crucial functions that you'll learn about below.
Initialization function
The first function you'll look at is the initialization function. This takes an owner_id
as the only parameter and will default all the storage collections to their default values.
Loading...