This project demonstrates a simple decentralized exchange (DEX) implementation that allows users to purchase an ERC20 token (VCoin) with Ether. The project includes the token contract, DEX contract, tests, and deployment scripts using Hardhat Ignition.
- VCoin (VC): A simple ERC20 token implementation based on OpenZeppelin's ERC20 standard
- DEX: A decentralized exchange contract that allows:
- Token purchase with ETH at a fixed price
- Liquidity provision by the owner
- ETH withdrawals by the owner
You can visit the frontend here.
- Fixed price token exchange
- Owner-controlled liquidity provision
- Comprehensive test coverage
- Hardhat Ignition deployment modules
- Node.js and npm
- Git
# Clone this repository
git clone <repository-url>
cd erc20_dex_demo
# Install dependencies
npm install
# Run all tests
npx hardhat test
# Run tests with gas reporting
REPORT_GAS=true npx hardhat test
Start a local Hardhat node:
npx hardhat node
In a new terminal window, deploy the contracts using Hardhat Ignition:
npx hardhat ignition deploy ./ignition/modules/Dex.ts
This will deploy both the VCoin token and the DEX contract.
After deployment, you can interact with the contracts:
- The owner can provide liquidity by calling
provideLiquidity(uint256 numTokens)
- Users can purchase tokens by calling
buy(uint256 numTokens)
with the appropriate ETH value - The owner can withdraw ETH from the contract using
withdraw(uint256 amount)
contracts/
- Smart contract source codeVCoin.sol
- ERC20 token implementationDex.sol
- DEX implementation
test/
- Test files for the contractsignition/modules/
- Hardhat Ignition deployment modules
This project is licensed under the MIT License - see the LICENSE file for details.