A decentralized exchange (DEX) built using React, Solidity, Truffle, and Ganache. This project demonstrates how to create a simple DEX on the Ethereum blockchain with a frontend powered by React.
- Introduction
- Features
- Project Structure
- Installation
- Running the Project
- Interacting with the DEX
- Troubleshooting
- License
This project is a simple decentralized exchange (DEX) that allows users to swap between two tokens, provide liquidity, and remove liquidity. The DEX is built on the Ethereum blockchain using Solidity for smart contracts and React for the frontend.
- Token Swap: Users can swap between two ERC-20 tokens.
- Add Liquidity: Users can provide liquidity to the pool and receive LP tokens.
- Remove Liquidity: Users can remove liquidity and redeem their LP tokens.
- Responsive UI: A user-friendly interface built with React.
├── client # React frontend
│ ├── public # Public files
│ └── src # React source code
│ ├── pages # frontend pages
│ ├── App.js # Main app component
│ └── index.js # React entry point
├── contracts # Solidity smart contracts
├── migrations # Truffle migrations
├── test # Truffle tests
├── truffle-config.js # Truffle configuration
└── README.md # Project documentation
- Node.js and npm
- Truffle
- Ganache
- MetaMask (or any Ethereum wallet browser extension)
- Clone the repository:
git clone https://github.com/actopas/simple-dex.git
cd simple-dex
- Install dependencies:
npm install
- Start Ganache:
ganache
- Start Ganache and make sure it runs on the default port
8545
.
- Compile and deploy the smart contracts then init it:
truffle compile
truffle migrate --reset
truffle exec ./scripts/init_dex.js
- Copy the buid\contracts TokenA and B and Dex Contract JSON file to src/contracts then copy the addressA and B and Dex to the pages/home inside
- Start the React frontend:
npm start
The app will be available at http://localhost:3000
.
-
Ensure Ganache is running and connected to the correct network.
-
Run Truffle migrations then init it to deploy the contracts to your local blockchain:
truffle migrate --reset
truffle exec ./scripts/init_dex.js
- Copy the buid\contracts TokenA and B and Dex Contract JSON file to src/contracts then copy the addressA and B and Dex to the pages/home inside
- Start the React development server:
npm start
Open http://localhost:3000
in your browser to view the app.
- Connect MetaMask: Ensure MetaMask is connected to the same network as Ganache.
- Add Liquidity: Use the interface to add liquidity to the pool.
- Swap Tokens: Swap between the available tokens.
- Remove Liquidity: Redeem your LP tokens and withdraw your liquidity.
- Contracts not deploying: Ensure Ganache is running and Truffle is connected to the correct network.
- MetaMask issues: Make sure MetaMask is connected to the Ganache network and the correct account is selected.
- Frontend not updating: Check the browser console for errors, and ensure the React app is properly connected to the blockchain.
This project is licensed under the MIT License - see the LICENSE file for details.