diff --git a/ENVIRONMENT_SETUP.md b/ENVIRONMENT_SETUP.md new file mode 100644 index 00000000..34dbdbd7 --- /dev/null +++ b/ENVIRONMENT_SETUP.md @@ -0,0 +1,312 @@ +# Environment Setup Guide + +This guide will help you set up your development environment for the Agora Blockchain project. + +## Table of Contents + +- [Prerequisites](#prerequisites) +- [Quick Start (Local Development)](#quick-start-local-development) +- [Testnet/Production Setup](#testnetproduction-setup) +- [Getting Credentials](#getting-credentials) +- [Troubleshooting](#troubleshooting) + +## Prerequisites + +Before you begin, ensure you have: + +1. **Node.js** (v18 or later) - [Download](https://nodejs.org/) +2. **npm** or **yarn** (comes with Node.js) +3. **Git** - [Download](https://git-scm.com/) +4. **MetaMask** browser extension - [Install](https://metamask.io/) +5. **(Optional) Docker Desktop** - [Download](https://www.docker.com/products/docker-desktop) - Only if using Docker setup + +### Verify Installation + +```bash +node --version # Should be v18 or higher +npm --version +git --version +``` + +## Quick Start (Local Development) + +For contributors who want to quickly test and develop without external services: + +### Step 1: Clone the Repository + +```bash +git clone https://github.com/AOSSIE-Org/Agora-Blockchain +cd Agora-Blockchain +``` + +### Step 2: Set Up Environment Files + +#### Option A: Using Scripts (Recommended) + +**For Linux/Mac:** +```bash +chmod +x setup-env.sh +./setup-env.sh +``` + +**For Windows (PowerShell):** +```powershell +.\setup-env.ps1 +``` + +#### Option B: Manual Setup + +**Blockchain Environment:** +```bash +cp blockchain/.env.example blockchain/.env +``` + +Edit `blockchain/.env` and use these local development values: +```env +PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +RPC_URL_SEPOLIA=http://localhost:8545 +RPC_URL_FUJI=http://localhost:8545 +RPC_URL_AMOY=http://localhost:8545 +RPC_URL_BSC=http://localhost:8545 +ETHERSCAN_KEY=dummy_key_for_local_dev +``` + +**Client Environment:** +```bash +cp client/.env.example client/.env +``` + +Edit `client/.env` with: +```env +NEXT_PUBLIC_SEPOLIA_RPC_URL=http://localhost:8545 +NEXT_PUBLIC_AMOY_RPC_URL=http://localhost:8545 +NEXT_PUBLIC_FUJI_RPC_URL=http://localhost:8545 +NEXT_PUBLIC_PINATA_JWT=dummy_jwt_for_local_dev +``` + +### Step 3: Start Development Environment + +#### Terminal 1: Start Local Blockchain +```bash +cd blockchain +npm install +npx hardhat node +``` + +Keep this terminal running. You'll see test accounts with 10000 ETH each. + +#### Terminal 2: Start Frontend +```bash +cd client +npm install +npm run dev +``` + +### Step 4: Access the Application + +- **Frontend**: http://localhost:3000 +- **Blockchain Node**: http://localhost:8545 + +### Step 5: Configure MetaMask (Optional) + +To interact with the local blockchain: + +1. Open MetaMask +2. Click on the network dropdown → Add Network → Add a network manually +3. Enter these details: + - **Network Name**: Hardhat Local + - **RPC URL**: http://localhost:8545 + - **Chain ID**: 31337 + - **Currency Symbol**: ETH +4. Import a test account using one of the private keys from the Hardhat node output + +⚠️ **Note**: These test accounts are publicly known. Never send real funds to them! + +## Testnet/Production Setup + +For deploying to testnets or production environments: + +### Step 1: Get Required Credentials + +You'll need: +1. **Wallet Private Key** (for a testnet wallet) +2. **RPC Provider URLs** (Alchemy, Infura, or QuickNode) +3. **Block Explorer API Keys** (Etherscan, Polygonscan, etc.) +4. **Pinata API Key** (for IPFS storage) + +See [Getting Credentials](#getting-credentials) section for detailed instructions. + +### Step 2: Configure Environment Files + +Copy the example files: +```bash +cp blockchain/.env.example blockchain/.env +cp client/.env.example client/.env +``` + +Edit both files with your actual credentials. The `.env.example` files contain detailed comments for each variable. + +### Step 3: Get Testnet Tokens + +You'll need test tokens for transactions: + +- **Sepolia (Ethereum)**: https://sepoliafaucet.com/ +- **Fuji (Avalanche)**: https://faucet.avax.network/ +- **Amoy (Polygon)**: https://faucet.polygon.technology/ +- **BSC Testnet**: https://testnet.bnbchain.org/faucet-smart + +### Step 4: Deploy and Test + +```bash +# Test contracts +cd blockchain +npx hardhat test + +# Deploy to testnet (example: Sepolia) +npx hardhat ignition deploy ./ignition/modules/YourModule --network sepolia --verify + +# Run frontend +cd ../client +npm run dev +``` + +## Getting Credentials + +### 1. Wallet Private Key + +**For Testing (Recommended):** +1. Create a new MetaMask wallet specifically for testing +2. Never use a wallet with real funds +3. Export the private key: MetaMask → Account Details → Export Private Key + +⚠️ **NEVER commit your private key to Git or share it publicly!** + +### 2. RPC Provider URLs + +Free RPC providers for blockchain access: + +#### Alchemy (Recommended) +1. Sign up at https://www.alchemy.com/ +2. Create a new app +3. Select your desired network (Sepolia, Polygon, etc.) +4. Copy the HTTPS endpoint + +#### Infura +1. Sign up at https://www.infura.io/ +2. Create a new project +3. Select your network +4. Copy the endpoint URL + +#### QuickNode +1. Sign up at https://www.quicknode.com/ +2. Create an endpoint +3. Select network and copy URL + +### 3. Block Explorer API Keys + +For contract verification: + +#### Etherscan (Ethereum networks) +1. Sign up at https://etherscan.io/ +2. Go to API Keys section +3. Create new API key + +#### Polygonscan (Polygon networks) +1. Sign up at https://polygonscan.com/ +2. Same process as Etherscan + +#### Snowtrace (Avalanche) +1. Sign up at https://snowtrace.io/ +2. Create API key in your account + +### 4. Pinata API Key (IPFS) + +For storing election metadata: + +1. Sign up at https://www.pinata.cloud/ +2. Go to API Keys section +3. Create new key with "pinFileToIPFS" permission +4. Copy the JWT token + +## Troubleshooting + +### Common Issues + +#### "Cannot find module" errors +```bash +# Reinstall dependencies +cd blockchain && npm install +cd ../client && npm install +``` + +#### "Port 3000 already in use" +```bash +# Kill the process using port 3000 +# Linux/Mac: +lsof -ti:3000 | xargs kill -9 + +# Windows: +netstat -ano | findstr :3000 +taskkill /PID /F +``` + +#### "Failed to connect to localhost:8545" +Make sure the Hardhat node is running in a separate terminal: +```bash +cd blockchain +npx hardhat node +``` + +#### MetaMask not connecting +1. Ensure you're on the correct network (Hardhat Local for local dev) +2. Try resetting your MetaMask account: Settings → Advanced → Reset Account + +#### Compilation errors with Hardhat +```bash +cd blockchain +npx hardhat clean +npx hardhat compile +``` + +#### Next.js build errors +```bash +cd client +rm -rf .next +npm run dev +``` + +### Getting Help + +If you're still facing issues: + +1. Check existing [GitHub Issues](https://github.com/AOSSIE-Org/Agora-Blockchain/issues) +2. Join the [Discord channel](https://discord.gg/HrJ6eKJ28a) +3. Create a new issue with: + - Your error message + - Steps to reproduce + - Your environment (OS, Node version, etc.) + +## Security Best Practices + +✅ **DO:** +- Use separate wallets for testing and production +- Keep private keys in `.env` files (already in `.gitignore`) +- Use testnet tokens for development +- Regularly rotate API keys + +❌ **DON'T:** +- Commit `.env` files to Git +- Share private keys or API keys +- Use production wallets with real funds for testing +- Store credentials in code files + +## Next Steps + +After setting up your environment: + +1. Read the main [README.md](README.md) for project overview +2. Check [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines +3. Review the [Architecture Documentation](docs/) +4. Start with "good first issue" labels on GitHub + +Happy Contributing! 🚀 diff --git a/README.md b/README.md index 9eccf153..d59c6f75 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,54 @@ Here's a refined version of the development guide: ## Development Guide +### Prerequisites + +Before you begin, ensure you have the following installed: +- **Node.js** (v18 or later): [Download here](https://nodejs.org/) +- **npm** (comes with Node.js) or **yarn** +- **Git**: [Download here](https://git-scm.com/) +- **MetaMask** browser extension: [Install here](https://metamask.io/) + +### Environment Setup + +The project requires environment variables for both blockchain and client components. We provide `.env.example` files with detailed comments to help you get started. + +#### Quick Setup for Local Development + +For quick local testing without external services: + +1. **Blockchain** (`blockchain/.env`): + ```bash + cp blockchain/.env.example blockchain/.env + ``` + You can use the default Hardhat test account values provided in the comments. + +2. **Client** (`client/.env`): + ```bash + cp client/.env.example client/.env + ``` + For local development, you can use dummy values (some features like IPFS upload won't work). + +#### Setup for Testnet/Production + +For deploying to testnets or production: + +1. Review the `.env.example` files in both `blockchain/` and `client/` directories +2. Each variable has detailed comments explaining: + - What the variable is used for + - Where to obtain the credentials + - Differences between local/testnet/mainnet usage +3. Copy the example files and fill in your actual credentials: + ```bash + cp blockchain/.env.example blockchain/.env + cp client/.env.example client/.env + ``` + +⚠️ **Security Notes**: +- NEVER commit `.env` or `.env.local` files to Git +- NEVER use wallets with real funds for testing +- Keep your private keys and API keys secure + ### Running Locally **Clone the Repository**: @@ -44,19 +92,14 @@ git clone https://github.com/AOSSIE-Org/Agora-Blockchain ``` 2. **Set up Environment Variables**: - - Create `.env.local` in the `blockchain` directory: - ``` - PRIVATE_KEY= - RPC_URL_SEPOLIA= - RPC_URL_FUJI= - ETHERSCAN_KEY= - ``` - - Create `.env.local` in the `client` directory: - ``` - NEXT_PUBLIC_PINATA_JWT= + + Copy the example environment files and configure them: + ```bash + cp blockchain/.env.example blockchain/.env + cp client/.env.example client/.env ``` + + Edit the `.env` files with your credentials. See the `.env.example` files for detailed instructions on each variable. 3. **Run with Docker Compose**: ```bash @@ -70,67 +113,66 @@ git clone https://github.com/AOSSIE-Org/Agora-Blockchain The application will automatically reload when you make changes to the source code. ### Option 2: Manual Setup -## Backend -1. **Navigate to the Blockchain Directory**: +#### Backend (Blockchain) + +1. **Navigate to the Blockchain Directory**: ```bash cd blockchain ``` 2. **Install Dependencies**: - ```bash npm install ``` -3. **Test the Contracts**: - +3. **Set up Environment Variables**: ```bash - npx hardhat test + cp .env.example .env ``` + Edit `.env` with your configuration (see `.env.example` for detailed instructions). + + For local development only, you can use: + ```bash + npx hardhat node + ``` + This starts a local blockchain at `http://localhost:8545` with test accounts. -4. **Create an `.env.local` file** with the following environment variables: - +4. **Test the Contracts**: ```bash - PRIVATE_KEY= - RPC_URL_SEPOLIA= - RPC_URL_FUJI= - ETHERSCAN_KEY= + npx hardhat test ``` -5. **Compile & Deploy Contracts**: +5. **Compile & Deploy Contracts** (Optional - for testnet deployment): ```bash npx hardhat ignition deploy ./ignition/modules/ --network --verify ``` -## Frontend +#### Frontend (Client) 1. **Navigate to the Client Directory**: - ```bash cd client ``` 2. **Install Dependencies**: - ```bash npm install ``` -3. **Run the Application**: - +3. **Set up Environment Variables**: ```bash - npm run dev + cp .env.example .env ``` + Edit `.env` with your configuration (see `.env.example` for detailed instructions). -4. **Create an `.env.local` file** with the following environment variables: - +4. **Run the Application**: ```bash - NEXT_PUBLIC_PINATA_JWT= + npm run dev ``` -5. **Visit the Live App at**: - **[localhost](http://localhost:3000/)** +5. **Visit the Application**: + Open [http://localhost:3000](http://localhost:3000) in your browser. ## About smart contracts diff --git a/blockchain/.env.example b/blockchain/.env.example index d26c2bc2..9dbe7219 100644 --- a/blockchain/.env.example +++ b/blockchain/.env.example @@ -1,6 +1,53 @@ -PRIVATE_KEY = ENTER_YOUR_KEY_VALUE -RPC_URL_SEPOLIA = ENTER_YOUR_KEY_VALUE -RPC_URL_FUJI = ENTER_YOUR_KEY_VALUE -RPC_URL_AMOY = ENTER_YOUR_KEY_VALUE -RPC_URL_BSC = ENTER_YOUR_KEY_VALUE -ETHERSCAN_KEY = ENTER_YOUR_KEY_VALUE +# ============================================ +# Blockchain Environment Configuration +# ============================================ +# Copy this file to .env or .env.local and fill in your values +# For local development, you can use dummy values +# For testnet/mainnet deployment, use real credentials + +# ============================================ +# PRIVATE KEY (Required for deployment) +# ============================================ +# For LOCAL DEVELOPMENT: Use Hardhat's default test account private key +# PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +# +# For TESTNET/MAINNET: Use your wallet's private key +# ⚠️ NEVER commit your real private key to Git! +# ⚠️ NEVER use a wallet with real funds for testing! +# Get a testnet private key from MetaMask (create a new test wallet) +PRIVATE_KEY=ENTER_YOUR_KEY_VALUE + +# ============================================ +# RPC URLs (Blockchain Network Endpoints) +# ============================================ +# For LOCAL DEVELOPMENT: Use local Hardhat node +# RPC_URL_SEPOLIA=http://localhost:8545 +# +# For TESTNET DEPLOYMENT: Get free RPC URLs from: +# - Alchemy: https://www.alchemy.com/ +# - Infura: https://www.infura.io/ +# - QuickNode: https://www.quicknode.com/ + +# Sepolia Testnet (Ethereum) +RPC_URL_SEPOLIA=ENTER_YOUR_KEY_VALUE + +# Fuji Testnet (Avalanche) +RPC_URL_FUJI=ENTER_YOUR_KEY_VALUE + +# Amoy Testnet (Polygon) +RPC_URL_AMOY=ENTER_YOUR_KEY_VALUE + +# BSC Testnet (Binance Smart Chain) +RPC_URL_BSC=ENTER_YOUR_KEY_VALUE + +# ============================================ +# ETHERSCAN API KEY (For contract verification) +# ============================================ +# For LOCAL DEVELOPMENT: Use dummy value +# ETHERSCAN_KEY=dummy_key_for_local_dev +# +# For TESTNET/MAINNET: Get free API key from: +# - Etherscan: https://etherscan.io/apis +# - Polygonscan: https://polygonscan.com/apis +# - Snowtrace (Avalanche): https://snowtrace.io/apis +ETHERSCAN_KEY=ENTER_YOUR_KEY_VALUE diff --git a/client/.env.example b/client/.env.example index 16d49007..3bb82b48 100644 --- a/client/.env.example +++ b/client/.env.example @@ -1,4 +1,45 @@ -NEXT_PUBLIC_SEPOLIA_RPC_URL = ENTER_RPC_URL -NEXT_PUBLIC_AMOY_RPC_URL = ENTER_RPC_URL -NEXT_PUBLIC_FUJI_RPC_URL = ENTER_RPC_URL -NEXT_PUBLIC_PINATA_JWT = ENTER_PINATA_API_KEY \ No newline at end of file +# ============================================ +# Client (Frontend) Environment Configuration +# ============================================ +# Copy this file to .env or .env.local and fill in your values +# For local development, you can use dummy values + +# ============================================ +# RPC URLs (Blockchain Network Endpoints) +# ============================================ +# These are PUBLIC variables (NEXT_PUBLIC_ prefix) +# They will be exposed to the browser +# +# For LOCAL DEVELOPMENT: Use local Hardhat node +# NEXT_PUBLIC_SEPOLIA_RPC_URL=http://localhost:8545 +# +# For PRODUCTION: Get free RPC URLs from: +# - Alchemy: https://www.alchemy.com/ (Recommended) +# - Infura: https://www.infura.io/ +# - QuickNode: https://www.quicknode.com/ + +# Sepolia Testnet (Ethereum) +NEXT_PUBLIC_SEPOLIA_RPC_URL=ENTER_RPC_URL + +# Amoy Testnet (Polygon) +NEXT_PUBLIC_AMOY_RPC_URL=ENTER_RPC_URL + +# Fuji Testnet (Avalanche) +NEXT_PUBLIC_FUJI_RPC_URL=ENTER_RPC_URL + +# ============================================ +# PINATA API (For IPFS file storage) +# ============================================ +# Used for storing election metadata and candidate information +# +# For LOCAL DEVELOPMENT: Use dummy value (some features won't work) +# NEXT_PUBLIC_PINATA_JWT=dummy_jwt_for_local_dev +# +# For PRODUCTION: Get free API key from: +# - Pinata: https://www.pinata.cloud/ (Sign up for free account) +# Steps: +# 1. Create account at https://app.pinata.cloud/register +# 2. Go to API Keys section +# 3. Create new API key with upload permissions +# 4. Copy the JWT token +NEXT_PUBLIC_PINATA_JWT=ENTER_PINATA_API_KEY \ No newline at end of file diff --git a/client/app/helpers/client.ts b/client/app/helpers/client.ts index c6d42f5d..15b2f53a 100644 --- a/client/app/helpers/client.ts +++ b/client/app/helpers/client.ts @@ -7,7 +7,7 @@ import { sepolia, polygonAmoy, avalancheFuji } from "wagmi/chains"; export const config = getDefaultConfig({ appName: "Agora-Blockchain", projectId: "8501447cf73c4e68061f7ed912d6a8ee", - chains: [sepolia, avalancheFuji], + chains: [sepolia, polygonAmoy, avalancheFuji], ssr: true, transports: { [sepolia.id]: http(process.env.NEXT_PUBLIC_SEPOLIA_RPC_URL), diff --git a/client/app/layout.tsx b/client/app/layout.tsx index 5d344e2f..616acea7 100644 --- a/client/app/layout.tsx +++ b/client/app/layout.tsx @@ -9,7 +9,7 @@ import { QueryClientProvider } from "@tanstack/react-query"; import { config, queryClient } from "./helpers/client"; import Header from "./components/Header/Header"; import Web3Connect from "./components/Helper/Web3Connect"; -import "rsuite/dist/rsuite-no-reset.min.css"; +import "rsuite/dist/rsuite.min.css"; import { CustomProvider } from "rsuite"; import ChatBot from "./components/ChatBot/ChatBot"; const inter = Inter({ subsets: ["latin"] }); diff --git a/setup-env.ps1 b/setup-env.ps1 new file mode 100644 index 00000000..e6d5d89d --- /dev/null +++ b/setup-env.ps1 @@ -0,0 +1,100 @@ +# Agora Blockchain - Environment Setup Script (PowerShell) +# This script helps you quickly set up environment files for local development + +Write-Host "🚀 Agora Blockchain - Environment Setup" -ForegroundColor Cyan +Write-Host "========================================" -ForegroundColor Cyan +Write-Host "" + +# Function to create blockchain .env file +function Setup-BlockchainEnv { + Write-Host "Setting up blockchain environment..." -ForegroundColor Yellow + + if (Test-Path "blockchain\.env") { + $overwrite = Read-Host "⚠️ blockchain\.env already exists! Do you want to overwrite it? (y/n)" + if ($overwrite -ne "y") { + Write-Host "Skipping blockchain\.env" + return + } + } + + $localDev = Read-Host "Are you setting up for local development? (y/n)" + + if ($localDev -eq "y") { + $content = @" +# Local Development Configuration +PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +RPC_URL_SEPOLIA=http://localhost:8545 +RPC_URL_FUJI=http://localhost:8545 +RPC_URL_AMOY=http://localhost:8545 +RPC_URL_BSC=http://localhost:8545 +ETHERSCAN_KEY=dummy_key_for_local_dev +"@ + Set-Content -Path "blockchain\.env" -Value $content + Write-Host "✅ Created blockchain\.env with local development values" -ForegroundColor Green + } + else { + Copy-Item "blockchain\.env.example" "blockchain\.env" + Write-Host "✅ Created blockchain\.env from example" -ForegroundColor Green + Write-Host "⚠️ Please edit blockchain\.env with your credentials" -ForegroundColor Yellow + } +} + +# Function to create client .env file +function Setup-ClientEnv { + Write-Host "Setting up client environment..." -ForegroundColor Yellow + + if (Test-Path "client\.env") { + $overwrite = Read-Host "⚠️ client\.env already exists! Do you want to overwrite it? (y/n)" + if ($overwrite -ne "y") { + Write-Host "Skipping client\.env" + return + } + } + + $localDev = Read-Host "Are you setting up for local development? (y/n)" + + if ($localDev -eq "y") { + $content = @" +# Local Development Configuration +NEXT_PUBLIC_SEPOLIA_RPC_URL=http://localhost:8545 +NEXT_PUBLIC_AMOY_RPC_URL=http://localhost:8545 +NEXT_PUBLIC_FUJI_RPC_URL=http://localhost:8545 +NEXT_PUBLIC_PINATA_JWT=dummy_jwt_for_local_dev +"@ + Set-Content -Path "client\.env" -Value $content + Write-Host "✅ Created client\.env with local development values" -ForegroundColor Green + Write-Host "⚠️ Note: IPFS uploads won't work with dummy Pinata JWT" -ForegroundColor Yellow + } + else { + Copy-Item "client\.env.example" "client\.env" + Write-Host "✅ Created client\.env from example" -ForegroundColor Green + Write-Host "⚠️ Please edit client\.env with your credentials" -ForegroundColor Yellow + } +} + +# Main execution +Write-Host "This script will help you set up environment variables." +Write-Host "" + +# Check if .env.example files exist +if (-not (Test-Path "blockchain\.env.example") -or -not (Test-Path "client\.env.example")) { + Write-Host "⚠️ Warning: .env.example files not found!" -ForegroundColor Yellow + Write-Host "Make sure you're running this script from the project root directory." + exit 1 +} + +Setup-BlockchainEnv +Write-Host "" +Setup-ClientEnv + +Write-Host "" +Write-Host "========================================" -ForegroundColor Cyan +Write-Host "✅ Environment setup complete!" -ForegroundColor Green +Write-Host "" +Write-Host "Next steps:" +Write-Host "1. Start blockchain: cd blockchain ; npx hardhat node" +Write-Host "2. Start frontend: cd client ; npm run dev" +Write-Host "3. Open http://localhost:3000" +Write-Host "" +Write-Host "For detailed instructions, see ENVIRONMENT_SETUP.md" +Write-Host "========================================" -ForegroundColor Cyan diff --git a/setup-env.sh b/setup-env.sh new file mode 100644 index 00000000..bf1fd8d5 --- /dev/null +++ b/setup-env.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +# Agora Blockchain - Environment Setup Script +# This script helps you quickly set up environment files for local development + +echo "🚀 Agora Blockchain - Environment Setup" +echo "========================================" +echo "" + +# Colors for output +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Function to create blockchain .env file +setup_blockchain_env() { + echo -e "${YELLOW}Setting up blockchain environment...${NC}" + + if [ -f "blockchain/.env" ]; then + echo "⚠️ blockchain/.env already exists!" + read -p "Do you want to overwrite it? (y/n): " overwrite + if [ "$overwrite" != "y" ]; then + echo "Skipping blockchain/.env" + return + fi + fi + + read -p "Are you setting up for local development? (y/n): " local_dev + + if [ "$local_dev" = "y" ]; then + cat > blockchain/.env << 'EOF' +# Local Development Configuration +PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +RPC_URL_SEPOLIA=http://localhost:8545 +RPC_URL_FUJI=http://localhost:8545 +RPC_URL_AMOY=http://localhost:8545 +RPC_URL_BSC=http://localhost:8545 +ETHERSCAN_KEY=dummy_key_for_local_dev +EOF + echo -e "${GREEN}✅ Created blockchain/.env with local development values${NC}" + else + cp blockchain/.env.example blockchain/.env + echo -e "${GREEN}✅ Created blockchain/.env from example${NC}" + echo -e "${YELLOW}⚠️ Please edit blockchain/.env with your credentials${NC}" + fi +} + +# Function to create client .env file +setup_client_env() { + echo -e "${YELLOW}Setting up client environment...${NC}" + + if [ -f "client/.env" ]; then + echo "⚠️ client/.env already exists!" + read -p "Do you want to overwrite it? (y/n): " overwrite + if [ "$overwrite" != "y" ]; then + echo "Skipping client/.env" + return + fi + fi + + read -p "Are you setting up for local development? (y/n): " local_dev + + if [ "$local_dev" = "y" ]; then + cat > client/.env << 'EOF' +# Local Development Configuration +NEXT_PUBLIC_SEPOLIA_RPC_URL=http://localhost:8545 +NEXT_PUBLIC_AMOY_RPC_URL=http://localhost:8545 +NEXT_PUBLIC_FUJI_RPC_URL=http://localhost:8545 +NEXT_PUBLIC_PINATA_JWT=dummy_jwt_for_local_dev +EOF + echo -e "${GREEN}✅ Created client/.env with local development values${NC}" + echo -e "${YELLOW}⚠️ Note: IPFS uploads won't work with dummy Pinata JWT${NC}" + else + cp client/.env.example client/.env + echo -e "${GREEN}✅ Created client/.env from example${NC}" + echo -e "${YELLOW}⚠️ Please edit client/.env with your credentials${NC}" + fi +} + +# Main execution +echo "This script will help you set up environment variables." +echo "" + +# Check if .env.example files exist +if [ ! -f "blockchain/.env.example" ] || [ ! -f "client/.env.example" ]; then + echo -e "${YELLOW}⚠️ Warning: .env.example files not found!${NC}" + echo "Make sure you're running this script from the project root directory." + exit 1 +fi + +setup_blockchain_env +echo "" +setup_client_env + +echo "" +echo "========================================" +echo -e "${GREEN}✅ Environment setup complete!${NC}" +echo "" +echo "Next steps:" +echo "1. Start blockchain: cd blockchain && npx hardhat node" +echo "2. Start frontend: cd client && npm run dev" +echo "3. Open http://localhost:3000" +echo "" +echo "For detailed instructions, see ENVIRONMENT_SETUP.md" +echo "========================================"