- Prerequisites
- MetaMask Setup
- Environment Setup
- Project Installation
- Development Server
- Smart Contract Deployment
- Troubleshooting
Before beginning the installation, ensure you have the following tools installed:
| Tool | Version | Purpose |
|---|---|---|
| Node.js | Latest LTS | JavaScript runtime |
| npm | Bundled with Node.js | Package manager |
| MetaMask | Latest | Blockchain interaction |
| PostgreSQL/NeonDB | Latest | Database management |
- Visit the MetaMask website
- Install the extension for your browser (Chrome, Firefox, Brave, or Edge)
- Click on the extension icon and follow the setup wizard
# For new wallet:
1. Click "Create a new wallet"
2. Set up a secure password
3. Store your 12-word seed phrase securely
4. Confirm your seed phrase
# For existing wallet:
1. Click "Import wallet"
2. Enter your 12-word seed phrase
3. Set up a new password
1. Click network dropdown (usually shows "Ethereum Mainnet")
2. Click "Add network"
3. Add Sepolia network details:
- Network Name: Sepolia Test Network
- RPC URL: https://sepolia.infura.io/v3/
- Chain ID: 11155111
- Currency Symbol: SepoliaETH
- Block Explorer: https://sepolia.etherscan.io
1. Copy your wallet address
2. Visit Sepolia faucet: https://sepoliafaucet.com
3. Request test ETH for development
1. Visit your local AgriChain application (http://localhost:3000)
2. Click "Connect Wallet" button
3. Select your MetaMask account
4. Approve the connection
# Clone the repository
git clone https://github.com/YOUR_REPOSITORY_URL.git
# Navigate to project directory
cd YOUR_PROJECT_DIRECTORYCreate the following environment files in their respective directories:
# API Configuration
API_PORT="YOUR_API_PORT" # Backend API port number
CONTRACT_ADDRESS="YOUR_CONTRACT_ADD" # Deployed Sepolia contract address
# Server Configuration
PORT=5000 # Backend server port
GEMINI_API_KEY="YOUR_GEMINI_API_KEY" # AI insights API key
DB_URL="YOUR_DB_URL" # Database connection URL
DB_PORT="YOUR_DB_PORT" # Database port number
# Blockchain Configuration
SEPOLIA_RPC_URL="https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY"
PRIVATE_KEY="YOUR_WALLET_PRIVATE_KEY" # ⚠️ Keep this secure
ETHERSCAN_API_KEY="YOUR_ETHERSCAN_API_KEY"
Tip
Create a copy of the .env.example and rename it to .env
Install all project dependencies with a single command:
# Install dependencies for all components
npm run install-allThis command installs dependencies for:
- Frontend application
- Backend server
- Smart contract development
Launch the development environment:
# Start all services
npm run devThis command initiates: (by default)
- Frontend server at
http://localhost:3000 - Backend server at
http://localhost:5000
For deploying smart contracts to the Sepolia testnet:
# Navigate to smart contracts directory
cd smart-contracts
# Deploy contracts
npx hardhat run scripts/deploy.js --network sepolia
# Verify on Etherscan (replace with your contract address)
npx hardhat verify --network sepolia YOUR_DEPLOYED_CONTRACT_ADDRESSCommon issues and solutions:
-
Port Conflicts
- Ensure ports 3000 and 5000 are available
-
Database Connection
- Verify database credentials in
.env - Ensure database service is running
- Verify database credentials in
-
Smart Contract Deployment
- Confirm sufficient test ETH in wallet
- Verify RPC URL and private key
- Check network connectivity
-
Environment Variables
- Double-check all
.envfiles are properly configured
- Double-check all
- Never commit
.envfiles to version control - Keep private keys secure and never share them
- Use test networks (Sepolia) for development
- Regularly update dependencies for security patches