A professional decentralized exchange (DEX) built on Uniswap V2 with Next.js 15, featuring institutional-grade UI and seamless Web3 integration.
- π Modern Architecture: Next.js 15 with App Router and
src/
directory structure - πΌ Professional UI: Satoshi font family with glassmorphism design
- π Web3 Integration: MetaMask wallet connection with auto-reconnection
- π Token Swapping: Real-time quotes via Uniswap V2 with slippage protection
- π± Responsive Design: Mobile-first approach with Tailwind CSS
- β‘ Performance Optimized: Fast loading with optimized bundle size
Category | Technology |
---|---|
Frontend | Next.js 15, React 19, TypeScript |
Styling | Tailwind CSS, Custom CSS |
Web3 | Ethers.js v5, MetaMask |
Blockchain | Ethereum Mainnet, Hardhat (development) |
DEX Protocol | Uniswap V2 |
- Node.js 18+ and npm
- MetaMask browser extension
- Git
-
Clone the repository
git clone https://github.com/yourusername/hashiraswap.git cd hashiraswap
-
Install dependencies
npm install
-
Set up environment variables (see Environment Setup)
-
Run development server
npm run dev
-
Open your browser Navigate to http://localhost:3000
Create a .env.local
file in the root directory:
# Alchemy API (Required for mainnet forking)
NEXT_PUBLIC_ALCHEMY_API_KEY=your_alchemy_api_key_here
# Commission Settings (Optional - for fee collection)
NEXT_PUBLIC_COMMISSION_ADDRESS=0x1234567890123456789012345678901234567890
NEXT_PUBLIC_COMMISSION_RATE=0.0001
# Development Settings (Optional)
NEXT_PUBLIC_NETWORK=mainnet
- Go to Alchemy
- Sign up for a free account
- Create a new app
- Select "Ethereum" β "Mainnet"
- Copy your API key
# .env.local
NEXT_PUBLIC_ALCHEMY_API_KEY=alch_1234567890abcdef1234567890abcdef
NEXT_PUBLIC_COMMISSION_ADDRESS=0x1234567890123456789012345678901234567890
NEXT_PUBLIC_COMMISSION_RATE=0.0001
This method creates a local blockchain fork with real mainnet data and gives you test ETH.
-
Start Hardhat fork
npm run fork
This starts a local blockchain at
http://localhost:8545
with 10,000 ETH in test accounts. -
In a new terminal, start the app
npm run dev
-
Configure MetaMask for local testing
Method 1: Manual Network Addition
- Network Name:
Ethereum Mainnet (Fork)
- RPC URL:
http://127.0.0.1:8545
- Chain ID:
1
(Important: Use 1, not 31337 for forked mainnet) - Currency Symbol:
ETH
- Block Explorer URL:
https://etherscan.io
(optional)
- Network Name:
-
Import a test account Use one of these pre-funded private keys:
0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
-
Run both fork and dev server together
npm run fork:dev
-
Get Sepolia ETH
-
Switch to Sepolia in MetaMask
- Network: Sepolia Test Network
- You'll need to modify the app to support Sepolia (currently mainnet only)
-
Get ETH
- Buy from exchanges (Coinbase, Binance, etc.)
- Bridge from other networks
-
Connect MetaMask to Ethereum Mainnet
hashiraswap/
βββ src/ # Source code (Next.js 13+ convention)
β βββ app/ # App Router pages
β β βββ layout.jsx # Root layout with Satoshi font
β β βββ page.jsx # Home page with integrated header
β β βββ loading.jsx # Loading UI
β β βββ error.jsx # Error boundary
β βββ components/ # React components
β β βββ SwapCard.jsx # Main trading interface
β β βββ WalletConnect.jsx # Wallet connection UI
β β βββ TokenModal.jsx # Token selection modal
β β βββ index.js # Component exports
β βββ context/ # React contexts
β βββ Web3Context.jsx # Web3 state management
βββ constants/ # Blockchain constants
β βββ abis.js # Smart contract ABIs
β βββ addresses.js # Contract and token addresses
βββ styles/ # Styling
β βββ globals.css # Global styles with Satoshi font
βββ public/ # Static assets
β βββ fonts/ # Satoshi font files
β βββ tokens/ # Token icons
βββ hardhat.config.js # Hardhat configuration
βββ package.json # Dependencies and scripts
Command | Description |
---|---|
npm run dev |
Start development server |
npm run build |
Build for production |
npm run start |
Start production server |
npm run lint |
Run ESLint |
npm run fork |
Start Hardhat mainnet fork |
npm run fork:dev |
Run fork and dev server together |
- USDT - Tether USD
- USDC - USD Coin
- DAI - Dai Stablecoin
- BUSD - Binance USD
- UNI - Uniswap
- AAVE - Aave
- LINK - Chainlink
- COMP - Compound
- CRV - Curve DAO
- MATIC - Polygon
- ARB - Arbitrum
- OP - Optimism
- SAND - The Sandbox
- MANA - Decentraland
- β No private keys stored
- β Client-side wallet connection only
- β Verified Uniswap V2 contract addresses
- β Slippage protection (0.5% default)
- β Transaction deadline limits (20 minutes)
- β Input validation and sanitization
- β Network verification (Ethereum Mainnet only)
1. "Please install MetaMask" error
- Install MetaMask browser extension
- Refresh the page after installation
2. "Wrong Network" warning
- Switch MetaMask to Ethereum Mainnet
- Or use Hardhat fork for testing
3. "Could not fetch chain ID" error when adding network
- Try
http://localhost:8545
instead ofhttp://127.0.0.1:8545
- Ensure Hardhat fork is running:
npm run fork
- Some firewalls block 127.0.0.1, try localhost instead
- Clear MetaMask cache: Settings β Advanced β Reset Account
4. "Insufficient ETH balance" error
- For testing: Use Hardhat fork with pre-funded accounts
- For mainnet: Ensure you have enough ETH for gas + swap amount
5. Transaction fails
- Check gas price isn't too high (>100 gwei)
- Ensure sufficient token balance
- Try increasing slippage tolerance
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow the existing code style
- Add TypeScript types where applicable
- Test with Hardhat fork before mainnet
- Update documentation for new features
- Ensure responsive design works on mobile
This project is licensed under the MIT License - see the LICENSE file for details.
- Uniswap for the DEX protocol
- Next.js for the amazing framework
- Ethers.js for Web3 integration
- Tailwind CSS for styling
- Satoshi Font for typography
Built with β€οΈ for the DeFi community
HashiraSwap - Professional DeFi Trading Platform