HugoBrunet13
NFT-Marketplace-Auction
TypeScript

NFT-Marketplace built with Solidity and tested with Hardhat framework

Last updated Nov 13, 2025
19
Stars
15
Forks
0
Issues
0
Stars/day
Attention Score
18
Language breakdown
No language data available.
โ–ธ Files click to expand
README

NFT-Marketplace [![Hardhat][hardhat-badge]][hardhat] [![typescript][typescript-badge]][typescript] [![License: MIT][license-badge]][license]

[hardhat]: https://hardhat.org/ [hardhat-badge]: https://img.shields.io/badge/Built%20with-Hardhat-FFDB1C.svg [license]: https://opensource.org/licenses/MIT [license-badge]: https://img.shields.io/badge/License-MIT-blue.svg [typescript]: https://www.typescriptlang.org/ [typescript-badge]: https://badgen.net/badge/icon/typescript?icon=typescript&label

Basic NFT Marketplace which enables NFT owners to list an ERC721 NFT for sales by creating new auctions. The creator of the auction must specify in which currency (ERC20 token) he wants buyers to place new bids on his auction.

Buyers can bid on available auctions. Their tokens will then be locked on the Marketplace contract. When the auction period is over, the winner can claim his reward (the NFT). This will also trigger the transfer of the money locked in the marketplace contract into the wallet of the creator of the auction.

When an auction is created for an NFT, the ownership of this NFT will be transfered from the creator of the auction to the Marketplace wallet. In case an auction ends without any new bid, the creator of the auction can be refunded. If an auction is over but the winner hasn't claimed his NFT yet, the creator of the auction can claim for his money. The payment tokens will then be transfered to the creator of the auction and the NFT will be sent to the winner of the auction. Most of the scenarios supported by this auction contract are covered in the testing file test/Marketplace.test.ts. (see bellow an overview of the tests).

Structure of the project

1. Smart contracts - contract/

Smart contract are implemented with Solidity and require the version 0.8.9 of the compiler.
  • ERC20.sol
Basic ERC20 Token contract that will be used by buyers to place new bid on an auction
  • NFTCollection.sol
ERC721 Token contract inherited from the openZepplin library: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol This contract will be used to mint new NFT, that will then be referenced in the auction created on the marketplace
  • Marketplace.sol
The Marketplace contract, main file of the project, where owners of NFTs can create new auctions and buyers will be able to place new bid.

2. Tests - test/

Unit tests for NFTCollection.sol and Marketplace.sol contracts.

3. Scripts - scripts/

Deployment scripts

How to run?

Stack

  • NodeJS (v >= 12.0.0)
  • npm
  • Hardhat
  • Solidity (v0.8.9)

Install dependencies and run tests

  • npm install
  • npx hardhat compile (to compile contracts and generate artifacts)
  • npx hardhat test (to run existing unit tests)
NB: Run npx hardhat test .\test\Marketplace.test.ts to only run test cases of the Marketplace.sol contract

Next steps?

  • Give more control on an existing auction to his creator. Example:
* Update endtime of an existing auction * Cancel auction with automatic refund
  • Enable auction creator to accept multiple ERC20 Token for payment
  • Build DApp to interact with the marketplace
  • Improve ERC721 implementation
  • Optmize unit tests of marketplace contract

Testing

Marketplace and NFTCollection contracts have been tested using Hardhat framework and Chai library. To run the test, please make sure all dependencies are installed and use the following command: npx hardhat test.

Below an overview of the tests for the Marketplace.sol contract

Marketplace contract
    Deployment
      โˆš Should set the correct name
      โˆš Should intialize auction sequence to 0
    Transactions - Create Auction
      Create Auction - Failure
        โˆš Should reject Auction because the NFT collection contract address is invalid
        โˆš Should reject Auction because the Payment token contract address is invalid
        โˆš Should reject Auction because the end date of the auction is invalid
        โˆš Should reject Auction because the initial bid price is invalid
        โˆš Should reject Auction because caller is not the owner of the NFT
        โˆš Should reject Auction because owner of the NFT hasnt approved ownership transfer
      Create Auction - Success
        โˆš Check if auction is created (61ms)
        โˆš Owner of NFT should be the marketplace contract 
    Transactions - Place new Bid on auction
      Place new Bid on an auction - Failure
        โˆš Should reject new Bid because the auction index is invalid
        โˆš Should reject new Bid because the new bid amount is invalid
        โˆš Should reject new Bid because caller is the creator of the auction
        โˆš Should reject new Bid because marketplace contract has no approval for token transfer
        โˆš Should reject new Bid because new bider has not enought balances (39ms)
      Place new Bid on an auction - Success
        โˆš Token balance of new bider must be debited with the bid amount
        โˆš Token balance of Marketplace contract must be updated with new bid amount
        โˆš Auction info are correctly updated
        โˆš Current bid owner must be refunded after a new successful bid is placed (72ms)
    Transactions - Claim NFT
      Claim NFT - Failure
        โˆš Should reject because auction is still open (125ms)
        โˆš Should reject because caller is not the current bid owner (111ms)
      Claim NFT - Success
        โˆš Winner of the auction must be the new owner of the NFT (152ms)
        โˆš Creator of the auction must have his token balance credited with the highest bid amount (151ms)
        โˆš Winner of the auction should not be able to claim NFT more than one time (158ms)
    Transactions - Claim Token
      Claim Token - Failure
        โˆš Should reject because auction is still open (127ms)
        โˆš Should reject because caller is not the creator of the auction (125ms)
      Claim Token - Success
        โˆš Winner of the auction must be the new owner of the NFT (152ms)
        โˆš Creator of the auction must have his token balance credited with the highest bid amount (151ms)
        โˆš Creator of the auction should not be able to claim his token more than one time (158ms)
    Transactions - Refund NFT
      Refund NFT - Failure
        โˆš Should reject because there is already a bider on the auction (140ms)
      Refund NFT - Success
        โˆš Creator of the auction must be again the owner of the NFT (89ms)

31 passing (9s)

Deployment

This project can be tested using Sepolia testnet and Infura. To deploy, you must first create a .env file and add 2 keys:

# .env  WALLETPRIVATEKEY=<YOUR SEPOLIA WALLET PRIVATE KEY> INFURAAPIKEY=<YOUR INFURA API KEY>

Then on hardhat.config.ts, uncomment the following lines:

// sepolia: {     //   url: https://sepolia.infura.io/v3/${INFURAAPIKEY},      //   accounts: [SEPOLIAPRIVATEKEY? SEPOLIAPRIVATEKEY : ""]     // }

Then, you can run this command: npx hardhat run scripts\Marketplace.deploy.ts --network sepolia

Make sure you have enough eth faucets before deploying. For more information, please check this tutorial: https://hardhat.org/tutorial/deploying-to-a-live-network.html

Documentation

  • Hardhat tutorials: https://hardhat.org/tutorial/
  • OpenZepplin contracts: https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/token
๐Ÿ”— More in this category

ยฉ 2026 GitRepoTrend ยท HugoBrunet13/NFT-Marketplace-Auction ยท Updated daily from GitHub