The Token-NFT Swap project introduces a swap contract that enables NFT owners to list their NFTs for sale with a specified amount of tokens. Token owners can then swap the designated tokens for the listed NFTs.
The primary goal of the Token-NFT Swap project is to:
- Target the DeFi Aspect: Address the decentralized finance (DeFi) aspect of the blockchain ecosystem by integrating the ERC20 and ERC721 standards, along with an intermediary Swap contract.
-
Comprehensive Documentation Using Natspec: The project is extensively documented using Natspec, providing thorough explanations of the functions and overall functionality of the Swap contract.
-
Unit Tests with ethers.js: The codebase features comprehensive unit tests written using
ethers.js
, ensuring the proper functionality of the implemented swap mechanisms. -
Deployment and Verification on Mumbai Polygon Testnet: The project has been deployed and verified on the Mumbai Polygon testnet. You can find the verified contract address on PolygonScan at the following link: Mumbai Polygon Testnet Contract
-
Swapping ERC20-ERC721 Process:
- The NFT owner registers the NFT for sale with a specified token amount in the Swap Contract.
- The NFT owner approves the Swap Contract to handle the NFT.
- The token owner approves the Swap Contract to handle the token amount required for the NFT purchase.
- The token owner calls the
swap(..)
function, specifying the desired NFT to purchase.
If the approved token amount matches the NFT's registered sale price, ownership of the NFT is swapped to the token owner, as well the previous NFT owner receive the specified token amount.
Note: The Token-NFT Swap project focuses on the DeFi landscape by enabling token-NFT swaps via a well-documented and tested contract. It is designed to showcase the integration of different standards and contract interactions within the blockchain ecosystem.
You can clone the repository and install its dependencies to start using the provided smart contracts.
$ git clone https://github.com/0xAdnanH/Token-NFT-Swap.git
$ cd ./Token-NFT-Swap
$ npm install
To Compile the contract run:
$ npx hardhat compile
To run the unit tests:
$ npx hardhat test