This is a Solidity smart contract for an NFT (Non-Fungible Token) marketplace. The contract allows users to mint, buy, and sell NFTs on the Ethereum blockchain. It is built using the ERC721 standard for NFTs and includes additional functionalities for managing token ownership, pricing, and transaction history.
Before using this contract, ensure that you have the following:
- Solidity version ^0.8.0
- OpenZeppelin Contracts library version 4.3.1
- OpenZeppelin ReentrancyGuard library version 4.3.1
Link to live Demo: >>NFTMarketplace :
NFT pageThis Project uses:
- Metamask
- Vite
- Goerli Faucet
- Infuria
- Truffle
- Solidity
- ReactJs
- Tailwind CSS
- Ganache-CLI
- Web3js
To run the program follow these steps:
-
Clone the project with the code below.
# Make sure you have the above prerequisites installed already! git clone https://github.com/LamsyA/GroupZee-Project # Navigate to the new folder. npm install # Installs all the dependencies.
-
Create an Infuria project, copy and paste your key in the spaces below.
-
Update the
.env
file with the following details.ENDPOINT_URL=<PROVIDER_URL> SECRET_KEY=<SECRET_PHRASE> DEPLOYER_KEY=<YOUR_PRIVATE_KEY>
-
Run the app using
npm run dev
- 👀 Web3Js
- 🎅 Faucet
- 🤖 Ganache
- 🤖 Vite
- ✨ Live Demo
- ⚽ Metamask
- 🚀 Remix Editor
- 💡 Truffle
- 📈 Infuria
- 🔥 ReactJs
- 🐻 Solidity
- Only the minter of an NFT or Artwork can change the price of the art work they minted.
- Others can only purchase the Artwork and take ownership of the Artwork they bought.
This contract imports the following dependencies from the OpenZeppelin Contracts library:
Counters
from@openzeppelin/contracts/utils/Counters.sol
: A library for managing numerical counters.ERC721
from@openzeppelin/contracts/token/ERC721/ERC721.sol
: A contract implementation of the ERC721 standard for NFTs.ReentrancyGuard
from@openzeppelin/contracts/security/ReentrancyGuard.sol
: A contract to prevent reentrancy attacks.
The NFTMarketplace
contract inherits from the ERC721
contract and uses the ReentrancyGuard
contract for security.
The main components of the contract are as follows:
Token
: A struct representing an NFT token, containing its owner, ID, token URL, title, price, description, and timestamp.transactions
: An array to store all token transactions.tokens
: A mapping to store each token by its ID.tokenIdNumber
: An array to keep track of all token IDs.
maxSupply
: The maximum supply of tokens that can be minted.owner
: The address of the contract owner.
TokenCreated
: Event emitted when a new token is created. It includes the sender, token ID, title, timestamp, token URL, and token price.TokenSold
: Event emitted when a token is sold. It includes the previous owner, new owner, and token ID.TokenPriceChanged
: Event emitted when the price of a token is changed. It includes the sender, token ID, and new price.
The constructor accepts the name, symbol, and owner address as parameters and initializes the contract by setting the owner.
nonReentrant
: A modifier provided byReentrancyGuard
to prevent reentrant function calls.
The contract provides the following external and public functions:
mint
: Creates a new NFT and mints it to the caller of the function.listNFTs
: Lists all NFTs in the marketplace.transactionHistory
: Retrieves the transaction history for all tokens.changePrice
: Changes the price of a token.buy
: Allows a user to buy a token.
- Deploy the
NFTMarketplace
contract to the Ethereum network. - Set the maximum supply of tokens and the owner address.
- Users can call the
mint
function to create and mint new NFTs to themselves. - The
listNFTs
function can be used to retrieve a list of all NFTs in the marketplace. - Users can change the price of their tokens using the
changePrice
function. - Other users can buy tokens using the
buy
function by sending enough ether to the contract. - The transaction history can be accessed through the
transactionHistory
function.
Note: Make sure to have the required
amount of ether in your account when calling functions that involve buying or changing token prices.
This project is licensed under the MIT License. See the LICENSE file for details.