A decentralized NFT marketplace enabling users to list, update, cancel, and purchase NFTs in a secure and transparent way. This project emphasizes robust smart contract design, comprehensive testing, and efficient gas usage.
- List NFTs for Sale: Owners can list their NFTs at a specified price.
- Update Listings: Sellers can update the price of their listed NFTs.
- Cancel Listings: Sellers can remove their NFTs from the marketplace.
- Purchase NFTs: Buyers can purchase listed NFTs securely.
- Full Test Coverage: All core functionalities are thoroughly tested.
- Gas Usage Insights: Gas consumption for all major operations is measured.
The marketplace is implemented in Solidity and follows a modular, test-driven approach. Below is a high-level overview of the contract structure and workflow:
Core Functions:
createListing
: List an NFT for sale (with checks for ownership, approval, and valid price).cancelListing
: Remove an NFT from the marketplace (only by the owner).updateListing
: Change the price of an existing listing (only by the owner).purchaseListing
: Buy a listed NFT (with payment and transfer validation).
Modifiers and Events:
- Modifiers ensure only valid actions (e.g., only the owner can update or cancel a listing).
- Events are emitted for all key actions, enabling easy integration with frontends or subgraphs.
The project includes detailed gas usage tracking for all major contract interactions, helping developers optimize and understand transaction costs.
Sample Gas Costs:
- Cancel Listing: 86,989
- Create Listing (Success): 108,000
- Purchase Listing (Success): 127,681
- Update Listing (Success): 109,859
Comprehensive tests ensure all functionalities work as intended and edge cases are handled. The project achieves 100% coverage across all files, statements, branches, and functions.
- All smart contract logic is fully tested.
- Edge cases (invalid prices, unauthorized actions, failed transfers) are covered.
- Mock contracts are used for simulating different scenarios.
src/NFT-Marketplace.sol
: Main marketplace contract.src/mocks/MockNFT.sol
: Mock NFT contract for testing.test/
: Contains all unit and integration tests.scripts/
: Deployment scripts.
Feel free to open issues or pull requests to suggest improvements, report bugs, or contribute new features.
This project is licensed under the MIT License.
- Built with Solidity, Foundry, and OpenZeppelin.
- Inspired by NFT marketplace project by Learnweb3.io
- solidity-by-example
- foundry fundamentals by cyfrin updraft
- foundry book
- ERC721 functions
- nft-marketplace project by allwin199
Note: This project is for educational and demonstration purposes. Do not use in production without a full security audit.