An NFT marketplace is a platform where NFTs (Non-Fungible Tokens) are browsed and traded through various mechanisms. Let's explore what building an NFT marketplace software entails.
The main goal of an NFT marketplace is to provide a trustworthy and secure way to facilitate the transfer of NFTs from one party to another. Operators of NFT marketplaces usually charge a fee for each transaction to provide this service. Additionally, some NFT marketplaces allow users to mint their NFTs on the platform itself and offer other additional features.
Each NFT marketplace operates according to its own system. The types of NFT standards available, fee structures, royalty payouts, payment options, trading mechanisms, supported blockchains, and other rules will vary depending on the marketplace you use. For example, OpenSea is a general-purpose marketplace, while Endemic and SuperRare focus on unique art.
These platforms offer a wide range of functionalities, including viewing NFTs and collections, supporting multiple NFT standards and cryptocurrencies, and accommodating various trading mechanisms, among others.
In a nutshell, an NFT marketplace allows you to browse and trade NFTs. Here is a breakdown of features you might encounter when visiting any of the popular marketplaces.
Depending on the marketplace, you will be able to browse all or a subset of NFTs available on the blockchain. The types of NFTs displayed to you are completely controlled by the marketplace. Some marketplaces support only the ERC-721 standard, while others also support ERC-1155.
Collections are a significant part of the NFT marketplace. The term 'collection' is another word for an NFT smart contract. Typically, the owner of a collection (contract) can modify the collection's description, upload profile and cover photos, add social links, etc., to the collection page. These pages serve as an entry point to the collection's NFTs. Not all collections are available on all marketplaces; this availability depends on what each marketplace decides to show.
Since the primary purpose of an NFT marketplace is to facilitate trades between NFT owners and collectors, it's natural for the marketplace to provide multiple trading mechanisms to support various use cases.
Some of these mechanisms include:
Instant buy The simplest mechanism allows the seller to set a fixed price for an NFT. Buyers see the price of the NFT and can initiate a transaction to purchase the item. Instant buy is usually conducted with main blockchain currencies such as ETH or MATIC, but it can also be implemented to support ERC20 tokens.
Dutch auction This type of auction allows the seller to set a higher starting price, a lower ending price, and the total duration of the auction. The price starts from the higher amount and linearly falls over time to the lower ending price. Once it reaches the ending price, it remains there. This allows sellers to obtain as much money as possible for their NFT, but the buyer determines how much the NFT is worth to them. Sometimes, buyers will wait until the price drops to the lowest ending price. However, since it operates on a first-come, first-served basis, another buyer might snatch the NFT right before their eyes. A Dutch auction is not a bidding mechanism; it’s similar to an instant buy but with a decreasing price.
Reserve auction Reserve auctions allow the seller to set up a minimum price they are willing to accept as a winning bid and determine the duration of the auction. Buyers can outbid each other until the time runs out. The highest bid wins, and the auction can be settled by either the seller or the buyer. This type of auction can be programmed with various rules to make the bidding more interesting, such as starting the timer only when the first bid is received or extending the bid window if the auction receives a bid in the last N minutes. The settlement of the reserve auction can occur after the time runs out and there is a winning bid.
Private sales Private sales allow the seller and buyer to arrange a price and use the marketplace's infrastructure to facilitate the trade, without any other users engaging in a public listing.
Offers Offers are very important because they enable buyers to express interest in NFTs that are either not for sale or when they wish to offer a lower price than listed. The owners of the NFT can choose to accept the offer or even create a counteroffer. The offer system is typically powered by ERC20 tokens due to their allowance mechanism.
NFT marketplaces typically charge a small fee on each transaction for providing their services. There are two types of fees:
Marketplaces usually charge only the maker fee, allowing the buyer to pay less.
Creator royalty is a small fee set by the artist or the company behind a project, taken from the sale price of any subsequent sale of an NFT. This fee typically ranges between 2.5% and 10% of the sale price.
An NFT marketplace can choose to enforce royalties on all trades or allow the buyer to decide if they want to respect the royalty setup for the collection.
NFT marketplace is usually a web application, but it’s a bit different from traditional web2 applications. It has two additional component, smart contracts and indexer service.
Technical components are:
Here's everything you should know about each of them.
In developing the frontend, you have the freedom to choose any technology that suits your needs. At Blank, we use React to create beautiful user experiences, leveraging the power and versatility of the React ecosystem. This ecosystem allows access to various packages, significantly reducing development time.
For an NFT marketplace, it's crucial to support different wallet providers, including Metamask, Coinbase, and WalletConnect, as users have varying preferences for wallets. Another important thing is to have well implemented smart contract interactions.
An excellent package for this purpose is 'wagmi,' a collection of React Hooks that offers comprehensive tools for working with Ethereum. Wagmi simplifies tasks like connecting wallets, displaying ENS and balance information, signing messages, and interacting with contracts, all while ensuring caching, request deduplication, and persistence. Another popular package for integrating with Ethereum is 'ethers,' a comprehensive, compact, and straightforward library for Ethereum, written in TypeScript.
Frontend application should handle all kinds of errors, validate states and update user about their transactions.
The purpose of the backend server is to supply all necessary data to the frontend application.
The complexity of the server will largely depend on the range of features supported by the marketplace and whether trading is conducted off-chain or on-chain. We will delve into the differences between these two methods in the next chapter.
Additionally, the backend may have a mechanism for communicating with the indexer service and vice versa, facilitating efficient data exchange and processing.
Smart contracts are the heart and soul of any NFT marketplace. Its where the most crucial activities occur.
Central to this is the exchange smart contract, which knows how to manage all trading mechanisms, transfer NFTs, and move funds. This contract must be exceptionally secure, as it is often the primary target for hackers, especially if your NFT marketplace is popular or if your smart contracts hold NFTs, Ether, or ERC20 tokens.
You have the option to either leverage existing, battle-tested smart contracts, such as SeaPort developed by OpenSea, or to build your own. The choice depends on your specific goals and your company's vision.
Some marketplaces also enable users to create collections and mint NFTs. To facilitate this, they implement collection templates, which are deployed when a user wishes to create a new collection. These collections are typically deployed using a proxy contract to minimize gas fees, making the process more efficient and cost-effective.
Processing blocks and extracting events relevant to the NFT marketplace, such as token mints, burns, transfers, approvals, and exchange events, are essential tasks.
The primary purpose of the indexer is to monitor blockchain data and create a data model that can be easily queried by either the frontend or backend.
It is good practice to make the indexer a separate service, arguably with a different database or schema than your main backend database. This design allows for the entire database to be easily dropped and the indexer restarted if needed. Since blockchain data is deterministic and immutable, it makes sense for the indexer service to be deterministic as well. This ensures that restarting it will always yield the same dataset in your database.
If an NFT marketplace supports multiple chains, it will need to operate multiple indexer services, one for each chain.
Arguably, an indexer is not strictly necessary to build an NFT marketplace, but not having one could either tightly couple your platform with data providers or result in slow and complex application code to display desired information. There are many providers of indexed data; however, for a serious business, building custom software becomes essential. It allows for the implementation of specific logic when processing blockchain data, emitting different events, and queuing jobs.
For an NFT marketplace MVP, using TheGraph indexer platform is a viable option. It allows for the rapid creation of a blockchain indexer and serves its purpose adequately. However, there are drawbacks to this approach, such as the inability to easily react to events triggered from your backend, difficulties in reindexing specific collections, and challenges in blacklisting certain NFTs from being indexed in real time.
We have used TheGraph and relied on it extensively in the past for building the MVP version of the Endemic marketplace. Now we run custom indexer software for all of our projects.
NFT marketplaces can be implemented with on-chain or off-chain trading mechanisms. Let's explore the differences between the two.
On-chain mechanisms place more logic within the smart contract, allowing it to serve as a business logic, validation, and settlement layer for executing trades between parties. In this scenario, actions such as listing an NFT for sale or creating an offer requires users to pay gas fees, with similar costs when canceling listings or offers. While this might be acceptable for highly popular marketplaces or those deployed on low gas cost networks like Polygon or any Layer 2 (L2) network, some users may find it off-putting to pay several dollars, or even tens of dollars in a bull market, to list their NFT on a new platform.
On-chain trading can be executed either with or without escrow. With escrow, the seller must transfer the NFT to the exchange's smart contract when listing it, and canceling the listing returns the NFT to its owner. This method prevents the simultaneous listing of the NFT on other marketplaces and removes the need for the marketplace to manage situations where a listed NFT is sold elsewhere. An example of a marketplace using escrow and on-chain trading is Foundation.
Alternatively, no escrow means the NFT never leaves the owner's wallet, allowing it to be listed on multiple marketplaces simultaneously. However, in this case, the marketplace must know to handle scenarios where the NFT is sold on another platform. The no escrow approach is advantageous as the platform never takes ownership of the user's NFTs, with trading facilitated through an approval mechanism in NFT standards that allows operators to transfer NFTs on behalf of users. OpenSea, Blur, Endemic and many other NFT marketplaces opt for no escrow trading.
An off-chain mechanism places more logic on the backend side, where smart contracts serve as a validation and settlement layer for executing trades between parties. In this setup, listing an NFT for sale or creating an offer does not require paying gas fees. Users only need to sign one transaction per collection to authorize the NFT marketplace to transfer NFTs on their behalf.
Listing an NFT involves EIP-712 signatures, where the marketplace constructs an object that the user signs with their wallet, a process that doesn't cost any gas. The signature is then validated and saved in the backend database. Buyers use the listing signature and provide funds to the exchange smart contract to complete the trade, paying gas fees in the process as these cannot be entirely avoided.
The creation of offers or bids for auctions follows a similar process: they are generated via signatures, stored in the database, and later sent to the smart contract to execute the trade.
Off-chain listing, creating offers, and bidding are beneficial as they spare users from gas fees, allowing them to create multiple listings, offers, or bids without any expenditure.
NFT metadata is essential, as it represents the digital assets associated with NFTs, typically in the form of images.
This metadata can be stored either on-chain, offering integrity and immutability but at a higher cost, particularly on networks like Ethereum with high transaction fees, or off-chain for more flexibility.
Off-chain storage can be on centralized servers such as AWS S3, which allows for dynamic NFTs with changeable metadata but requires trust in the service provider. Alternatively, decentralized platforms like IPFS provide enhanced security against alterations.
NFT marketplaces face the challenge of displaying a vast array of different images, often with no strong limits on file size.
This can include NFTs with large files, such as 100MB images or 1GB videos, which the marketplaces need to display efficiently.
To address this, NFT marketplaces should either use existing solutions for caching and optimizing metadata images or develop their own systems. By doing so, they effectively copy metadata from IPFS or other providers to their own storage, optimizing and caching it to ensure a smooth user experience.
When creating any smart contract, and especially NFT marketplaces, it’s crucial to invest in security audits.
Investing in security audits for smart contracts is particularly important for several reasons:
Protection of high-value assets NFTs often represent significant financial value, sometimes in the millions of dollars. A vulnerability in a smart contract can lead to the loss or theft of these high-value assets, resulting in substantial financial damage to users and the platform.
Ensuring authenticity and ownership The core value proposition of NFTs is their ability to prove authenticity and ownership. Security flaws could undermine these fundamental aspects, allowing for counterfeit NFTs or unauthorized transfers, damaging the credibility of the marketplace.
User confidence and market reputation Trust is paramount in NFT transactions. Security breaches can erode user confidence, leading to a decrease in participation and transactions on the platform. Maintaining a secure environment is essential for the marketplace's reputation and ongoing success.
Regulatory scrutiny and compliance As NFTs gain popularity, they attract more regulatory attention. Ensuring that smart contracts are secure and comply with relevant laws and regulations is crucial to avoid legal issues and penalties.
Complex transactions and unique features NFT marketplaces often implement complex and unique features in their smart contracts, such as bidding mechanisms. Security audits help ensure these features function as intended without vulnerabilities.
Interoperability concerns NFTs are often traded across different platforms and blockchains. Ensuring security in smart contracts is essential to maintain interoperability and prevent vulnerabilities that could arise from interactions between different systems.
Long-term viability For an NFT marketplace to thrive in the long term, it needs to establish a track record of security and reliability. Regular security audits are a key component of demonstrating a commitment to protecting users and their assets.
Building an NFT marketplace presents an awesome technical challenge. From the UI to smart contracts, there are many moving parts and things to consider.
Our team loves technical challenges, so feel free to reach out if you want to discuss building NFT marketplaces. We are happy to assist you!