A marketplace for buying/selling NFTs using Ethereum.
- List NFTs for easy sale.
- Cancel your NFT listing whenever you want.
- Buy NFTs using Ethereum.
- All smart contract functions tested.
- Framework CLI -> Foundry.
- Forge version -> 1.1.0-stable.
- Solidity compiler version -> 0.8.24.
- Clone the GitHub repository.
- Open Visual Studio Code (you should already have Foundry installed).
- Select "File" > "Open Folder", select the cloned repository folder.
- In the project navigation bar, open the "NFTMarketplace.sol" file located in the "src" folder.
- In the toolbar above, select "Terminal" > "New Terminal".
- Select the "Git bash" terminal (previously installed).
- Run the
forge buildcommand to compile the script. - In the project navigation bar, open the "NFTMarketplace.t.sol" file located in the "test" folder.
- Run the command
forge test --match-testfollowed by the name of a test function to test it and verify the smart contract functions are working correctly. For example, runforge test --match-test testMintNFT -vvvvto test thetestMintNFTfunction. - Run
forge coverageto generate a code coverage report, which allows you to verify which parts of the "NFTMarketplace.sol" script code (in the "src" folder) are executed by the tests. This helps identify areas outside the coverage that could be exposed to errors/vulnerabilities.
listNFT()-> Puts an NFT up for sale using the parameters seller, nftaddress, tokenId, and pricebuyNFT()-> Allows any user to purchase the listed NFTs.cancelList()-> Allows the owner of a listed NFT to cancel the sale of the NFT at any time.
testMintNFT()-> Verify that the NFT has been correctly minted to the user to perform the tests.testShouldRevertIfPriceIsZero()-> The test reverts if the price of the NFT to be listed is 0.testShouldRevertIfNotOwner()-> The test reverts if a user tries to list an NFT they do not own.testListNFTCorrectly()-> Verify that the user correctly lists the NFT.testCancelListShouldRevertIfNotOwner()-> The test reverts if a user tries to cancel the sale of an NFT they do not own.testCancelListShouldWorkCorrectly()-> Verifies that a user can successfully cancel a listed NFT they own.testCanNotBuyUnlistedNFT()-> The test should revert if you try to buy an NFT that is not listed by a user.testCanNotBuyWithIncorrectPay()-> The test reverts if a user attempts to purchase an NFT with an amount different from the price. It must be the exact same amount of Ether as the price of the NFT.testShouldBuyNFTCorrectly()-> Verify that any user can successfully purchase an NFT.
CODE IS LAW!