This repository contains a DeFi project built with Next.js and Solidity. It includes a smart contract component for blockchain interactions, a frontend interface for user interaction, and utilizes TypeScript for development.
- Smart Contract Integration: Facilitates interactions with decentralized protocols.
- Token Management: Includes token creation and management functionalities via smart contracts.
- Uniswap Clone: Demonstrates a basic implementation of a decentralized exchange (DEX).
- Modern Frontend: Built with Next.js for a responsive and user-friendly experience.
- Type Safety: Developed in TypeScript, providing enhanced code maintainability and fewer runtime errors.
Before you begin, ensure you have the following installed:
- Node.js: (Recommended version: >=18)
- npm or yarn or pnpm or bun
- Hardhat: For compiling and deploying smart contracts.
- Metamask or similar Ethereum wallet extension: For interacting with the deployed smart contracts.
Follow these steps to get the project up and running:
-
Clone the Repository:
git clone https://github.com/AdityasWorks/defi.git cd defi -
Install Dependencies:
npm install # or yarn install or pnpm install or bun install -
Navigate to Blockchain Directory and Install Dependencies
cd blockchain npm install # or yarn install or pnpm install or bun install
-
Configure Hardhat:
- Edit the
blockchain/hardhat.config.tsfile to set up your desired network configuration. Ensure to set your RPC URL and private key in a.envfile located in theblockchaindirectory. The example below shows how to configure the Sepolia test network:
import { HardhatUserConfig } from "hardhat/config"; import "@nomicfoundation/hardhat-toolbox"; import dotenv from "dotenv"; dotenv.config(); const RPC_URL = process.env.RPC_URL; const PRIVATE_KEY = process.env.PRIVATE_KEY; const config: HardhatUserConfig = { solidity: "0.8.28", networks: { sepolia: { url: RPC_URL, accounts: PRIVATE_KEY ? [PRIVATE_KEY] : [], }, }, }; export default config;
- Edit the
-
Deploy Smart Contracts:
- Run the deployment script located in
blockchain/scripts/deploy.tsto deploy your contracts to the configured network.
cd blockchain npx hardhat compile npx hardhat run scripts/deploy.ts --network sepolia- Alternatively, to deploy only the TokenFactory contract use:
npx hardhat run scripts/deployTokenFactory.ts --network sepolia
- Run the deployment script located in
-
Frontend Configuration:
- Create a
.envfile in the main directory with environment variables such as contract addresses after deployment. These addresses will be used by the frontend to interact with the contracts. Example:
NEXT_PUBLIC_TOKEN_FACTORY_ADDRESS=0xYourTokenFactoryContractAddress - Create a
-
Run the Development Server:
cd .. #Navigate back to main directory npm run dev # or yarn dev or pnpm dev or bun dev
Open http://localhost:3000 in your browser to view the application.
Once the contracts are deployed, you can interact with them via the frontend. The src/app/abis directory contains the contract ABIs. The frontend components use these ABIs to call the contract functions.
- Navigate to the "Token Factory" section.
- Fill in the name, symbol, and total supply of the token.
- Click the "Create Token" button.
- Approve the transaction in your Metamask wallet.
- Environment Variables:
NEXT_PUBLIC_TOKEN_FACTORY_ADDRESS: The address of the deployed TokenFactory contract.RPC_URL: The RPC URL for your Ethereum network (e.g., Infura or Alchemy).PRIVATE_KEY: Your private key for deploying contracts. (Use with caution, preferably for testing only. Consider using a secure solution like environment variables or a hardware wallet for production.)
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes with descriptive commit messages.
- Push your changes to your fork.
- Submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
- This project leverages libraries and tools from the Ethereum development community, including Hardhat, Ethers.js, and OpenZeppelin contracts.
- Next.js is used for the frontend.