NFT Marketplace E-Book
NFT Marketplace E-Book
NFT Marketplace E-Book
Since we are still early in the game regarding NFTs and their use
cases, who knows, any developer aspiring to become a blockchain
developer might be the one creating the next big NFT marketplace
that the masses will adopt. Of course, there will always be major NFT
marketplaces, but it makes sense for every NFT launch or collection to
have its own NFT marketplace. Moreover, you might get the next
opportunity to develop a marketplace devoted to NFTs for a large
blockchain company. As such, being able to create an NFT
marketplace is a skill that could future-proof your career, and with the
help of Moralis, it is a skill you can easily master.
What is an NFT Marketplace?
Before we take on an example project that will teach you how to
create an NFT marketplace with minimal effort and in record time, we
need to make sure you know all the basics. An NFT marketplace is
essentially any Web3 application that revolves around selling and
buying any kind of non-fungible token (NFT). As such, there can be
many kinds of NFT marketplaces such as one open to the general
public, where anyone with a crypto wallet can buy and list their own
NFTs. On the other hand, there are also NFT marketplaces that aren’t
open to the public. Specifically, these only let a particular company or
brand sell their NFTs, and do not allow users to list their NFTs.
If you prefer video format, you can watch our full tutorial video on our
Youtube channel by clicking here.
Before we start with the coding part, we want you to have a clear
picture of what we will build. Looking at the image below, you can see
that our example NFT marketplace will offer users multiple options
and features, including:
After you purchase the NFT, it is no longer in the “On Sale” section.
Instead, it shows in the “Your NFTs” section for the account (keep in
mind that it may take a while for the transaction to complete):
Once the transaction is complete, the new owner can sell that NFT.
How to Create an NFT Marketplace with Moralis
Now that we know what we will build, it is time to list the backend
features and components required to make the functionalities
displayed in line with what we’ve covered in the previous section.
If you prefer video format, you can watch our full tutorial video on our
Youtube channel by clicking here.
The gist of the smart contract used for our example can be seen by
looking at the events it covers:
contract MarketPlace{
This is the part that probably interests you the most. Here’s where we
ensure that the users get to see and use our NFT marketplace. For
the purpose of our example project, we created three files: “logic.js”,
“cloudCode.js”, and “index.html”. The complete code for each file is
also available on GitHub. We ensure the main functionality of our
dApp with the “logic.js” file. As such, it deserves some extra attention.
This is also where the full power of Moralis gets to be put to action.
Moreover, to initialize Moralis, you need to paste your Moralis server
URL and application ID:
Moralis.authenticate().then(function(){
populateNFTs();
populateOfferings();
populateBalance();
subscribeOfferings();
subscribeBuys();
subscribeUpdateNFTs();
});
The remaining code ensures that the “populate” and “subscribe”
functions obtain the proper data. Moreover, this means sure that
everything gets neatly displayed for our users. Moralis does all heavy
backend lifting through the use of code snippets that obtains data from
your “moralisDashboard” database. These snippets of code include:
● Moralis.Query(“PlacedOfferings”)
● Moralis.Query(“ClosedOfferings”)
● Moralis.Query(“PolygonNFTOwners”)
● Moralis.Cloud.run(“getBalance”, params)
● Moralis.Units.FromWei(presentBalance)
● Moralis.Cloud.run(“placeOffering”, params)
● Moralis.Units.ETH(offering.price)
Ensuring Proper Security of an NFT Marketplace
Of all the code snippets above, the “Moralis.Cloud.run(“placeOffering”,
params)” bears an extra significance. It enables us to ensure that our
dApp signs the transactions behind the curtains and protects our
dApp’s private key. This is also where the “cloudCode.js” file comes to
play. Inside it, we add the private key that corresponds to the specific
Ethereum address that you are using.
Make sure to checkout the full code on our Github. If you’re interested
in building more dApps like wallets, portfolio trackers, NFT games,
make sure to check out this Ethereum Boilerplate in React. It has all
important components and hooks for building dApps with React.