🚀 Deployment Guide

Prerequisites

1. Clone & Install

git clone https://github.com/Men6d656e/DEX.git
cd DEX
make install

This installs Foundry dependencies (forge install) and frontend npm packages.

2. Build Contracts

make build-contracts

3. Run Tests

# All tests
make test

# Just contract tests (182+ Solidity tests)
make test-contracts

# Just frontend tests
make test-frontend

# Coverage report (LCOV)
make coverage

4. Local Development (Anvil)

Start a local Anvil node in Terminal 1:

make anvil

In Terminal 2, deploy contracts (one command does it all):

make deploy-anvil

This will:

  1. Build contracts
  2. Prompt you interactively for a private key (via --interactives 1)
  3. Deploy all contracts (MockERC20 × 3, Faucet, MockDEX) to Anvil
  4. Add initial liquidity to the DEX
  5. Auto-capture the deployed contract addresses into frontend/src/lib/constants.ts

💡 For Anvil, use one of the default private keys printed when Anvil starts (e.g., 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80).

Start the Frontend

make dev

This installs any missing frontend dependencies and starts the dev server at http://localhost:3000 with hot reload.

5. Sepolia Testnet

Configure Environment

Create contracts/.env from the template:

cp contracts/.env.example contracts/.env

Edit contracts/.env with your Sepolia RPC URL and Etherscan API key:

# Sepolia RPC URL (from Alchemy, Infura, or your provider)
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY

# Etherscan API key (for contract verification)
ETHERSCAN_API_KEY=YOUR_ETHERSCAN_API_KEY

Deploy to Sepolia

make deploy-sepolia

This will:

  1. Build contracts
  2. Load SEPOLIA_RPC_URL and ETHERSCAN_API_KEY from contracts/.env
  3. Prompt you interactively for a private key
  4. Deploy all contracts to Sepolia
  5. Verify contracts on Etherscan (--verify)
  6. Auto-capture addresses into frontend/src/lib/constants.ts
âš ī¸

Make sure your wallet has Sepolia test ETH for gas. You can get it from sepoliafaucet.com.

Contract Verification

The --verify flag automatically submits your source code to Etherscan after deployment. You can then view your contracts with a "Verified" badge on the Sepolia Etherscan explorer.

6. Manual Address Update

If you need to re-capture addresses without redeploying (e.g., after a git checkout reverted constants.ts):

make update-addresses CHAIN_ID=31337   # For Anvil
make update-addresses CHAIN_ID=11155111 # For Sepolia

This parses the latest broadcast/Deploy.s.sol/run-latest.json and writes to frontend/src/lib/constants.ts.

7. Production Build

make prod

This builds the frontend (npm run build) and starts the production server at http://localhost:3000.

Deploying to Vercel

The frontend is ready for Vercel deployment:

  1. Push the repository to GitHub
  2. Import the project in Vercel
  3. Set the Root Directory to frontend
  4. Add environment variable NEXT_PUBLIC_COINGECKO_API_KEY (optional, for CoinGecko market data)
  5. Deploy

8. CoinGecko API Key (Optional)

To use live market data instead of simulated charts:

  1. Get a free API key from CoinGecko
  2. For local development, create frontend/.env.local:
    NEXT_PUBLIC_COINGECKO_API_KEY=your_api_key_here
  3. For production (Vercel), add as an environment variable in the project settings
â„šī¸

Without a CoinGecko API key, the frontend falls back to simulated market data. The app works fine either way.

9. Makefile Reference

Command Description
make installInstall all dependencies (forge + npm)
make buildBuild contracts + frontend
make testRun all tests
make anvilStart local Anvil node (port 8545)
make deploy-anvilDeploy to Anvil + auto-update addresses
make deploy-sepoliaDeploy to Sepolia + verify + auto-update
make update-addressesRe-capture addresses from broadcast JSON
make devInstall frontend deps + start dev server
make prodBuild + serve production
make coverageGenerate Foundry coverage report
make fmtFormat Solidity + TypeScript
make generate-abiGenerate wagmi type-safe hooks
make cleanClean all artifacts