This is a full-stack NFT marketplace project that includes smart contracts, a decentralized application (dApp), and an event indexer for a complete and efficient user experience.
This project implements an NFT marketplace where users can list, buy, and view NFTs. The architecture is divided into three main components:
- Smart Contracts: The blockchain backend, which manages the logic for NFTs and marketplace transactions.
- dApp Frontend: The web user interface that users interact with.
- Indexer: A service that listens for blockchain events and stores them so the dApp can query them efficiently.
The repository is organized as a monorepo containing the following packages:
foundry-nft/: Contains the Solidity smart contracts developed with Foundry. This is where the NFTs and marketplace logic are defined.dapp-nft/: A Next.js application that serves as the frontend. It allows users to connect their wallets, view NFTs, list them for sale, and purchase them.marketplaceIndexer/: The indexing service configured with Rindexer to track and record events from the smart contracts, such asItemListed,ItemBought, andItemCanceled.
-
Blockchain:
- Solidity: For writing smart contracts.
- Foundry: For contract compilation, testing, and deployment.
- OpenZeppelin Contracts: For implementing token standards (ERC721) and security utilities.
-
Frontend:
- Next.js: React framework for server-side rendering and static site generation.
- TypeScript: For static typing in the dApp's codebase.
- RainbowKit: for easy wallet integration.
- Tailwind CSS: For UI design.
- pnpm: Efficient package manager for the monorepo.
-
Indexer:
Before you begin, ensure you have the following tools installed:
- Node.js (v18 or higher)
- pnpm
- Foundry (Forge & Anvil)
- Docker and Docker Compose
-
Clone the repository:
git clone <REPOSITORY_URL> cd nft-marketplace
-
Install dApp dependencies:
cd dapp-nft pnpm install cd ..
-
Initialize Foundry submodules and build the contracts:
cd foundry-nft make install make build cd ..
To run the full project, you will need to have each component running in separate terminals.
-
Start a local Anvil network:
anvil
-
Run contract tests:
cd foundry-nft forge test
-
Deploy the contracts to the local network (or your chosen network):
cd foundry-nft forge script script/DeployBasicNft.s.sol --rpc-url <RPC_URL> --private-key <PRIVATE_KEY> --broadcast forge script script/DeployMoodNFT.s.sol --rpc-url <RPC_URL> --private-key <PRIVATE_KEY> --broadcast
Replace
<RPC_URL>and<PRIVATE_KEY>with the corresponding values.
-
Navigate to the dApp directory:
cd dapp-nft -
Create a
.env.localfile and configure the necessary environment variables (contract addresses, indexer API URL, etc.). -
Start the development server:
pnpm dev
The application will be available at http://localhost:3000.
-
Ensure the contract ABIs are up-to-date in the
marketplaceIndexer/abisdirectory. -
Configure
rindexer.yamlwith the deployed contract addresses and the RPC node URL. -
Start the indexer service with Docker Compose:
cd marketplaceIndexer docker-compose upThe indexer will start listening for blockchain events and storing them.
