Skip to content

Repository files navigation

EduChain AI 🎓

Decentralized AI-Powered Educational Assessment & NFT Certification System

SolidityPythonReactNetwork


📌 Overview

EduChain AI is a decentralized educational platform that combines Artificial Intelligence with Blockchain Technology to evaluate students and issue tamper-proof NFT certificates.

  • AI Layer — KNN Classifier analyzes student performance (score, attempts, time)
  • Blockchain Layer — Smart Contract validates and mints ERC-721 Soulbound NFTs
  • Storage Layer — NFT metadata stored permanently on IPFS via Pinata

🏗️ System Architecture

Student → Frontend (React) → AI Backend (FastAPI) ↓ Validator signs transaction ↓ Smart Contract (Sepolia) ↓ NFT Minted to Student Wallet


🛠️ Tech Stack

LayerTechnology
Smart ContractSolidity 0.8.26, OpenZeppelin, Hardhat
BlockchainEthereum Sepolia Testnet
FrontendReact.js, Ethers.js, Tailwind CSS
AI BackendPython, FastAPI, Scikit-learn (KNN)
StorageIPFS, Pinata
WalletMetaMask

📁 Project Structure

EduChain/ ├── contracts/ │ └── EduChain.sol # Smart Contract ├── scripts/ │ └── deploy.js # Deployment Script ├── test/ │ └── EduChain.test.js # Unit Tests ├── frontend/ │ └── src/ │ ├── App.jsx │ └── components/ │ ├── Navbar.jsx │ ├── Quiz.jsx │ ├── Result.jsx │ └── Verify.jsx ├── backend/ │ └── main.py # AI Backend ├── hardhat.config.js ├── .env └── README.md


⚙️ Installation & Setup

Prerequisites

  • Node.js v20+
  • Python 3.10+
  • MetaMask Browser Extension

1️⃣ Clone & Install Dependencies

# Install Hardhat dependencies
npm install
# Install Frontend dependenciescd frontend
npm install
cd ..
# Install Backend dependenciescd backend
python -m venv venv
venv\Scripts\activate
pip install fastapi uvicorn scikit-learn numpy web3 python-dotenv httpx
cd ..

2️⃣ Environment Variables

Create .env in root folder:

PRIVATE_KEY=your_wallet_private_key SEPOLIA_RPC_URL=your_alchemy_sepolia_url ETHERSCAN_API_KEY=your_etherscan_api_key

Create .env in backend/ folder:

PRIVATE_KEY=your_validator_private_key SEPOLIA_RPC_URL=your_alchemy_sepolia_url CONTRACT_ADDRESS=your_deployed_contract_address PINATA_JWT=your_pinata_jwt_token


3️⃣ Compile Smart Contract

npx hardhat compile

4️⃣ Run Tests

npx hardhat test

Expected output:

EduChain Happy Path ✔ Should mint NFT certificate for passing student Failed Validation ✔ Should revert if score is below minimum ✔ Should revert if attempts exceed maximum Unauthorized Access ✔ Should revert if caller is not the validator 4 passing


5️⃣ Deploy to Sepolia

npx hardhat run scripts/deploy.js --network sepolia

Copy the contract address and update it in:

  • backend/.envCONTRACT_ADDRESS
  • frontend/src/App.jsxCONTRACT_ADDRESS
  • frontend/src/components/Result.jsxCONTRACT_ADDRESS
  • frontend/src/components/Verify.jsxCONTRACT_ADDRESS

6️⃣ Run the Application

Terminal 1 — AI Backend:

cd backend
venv\Scripts\activate
uvicorn main:app --reload

Terminal 2 — Frontend:

cd frontend
npm run dev

Open browser at: http://localhost:5173


🔄 How It Works

  1. Student connects MetaMask wallet
  2. Student takes quiz (10 random questions from 50)
  3. Each question has a 30-second timer
  4. AI Backend analyzes: score (60%) + attempts (25%) + time (15%)
  5. KNN Classifier determines performance level
  6. If passed → Student mints NFT Certificate
  7. Validator Backend signs and submits to Smart Contract
  8. Contract verifies and mints Soulbound ERC-721 NFT
  9. If failed → Attempt recorded on blockchain automatically
  10. After 3 failed attempts → Wallet permanently banned

🔐 Security Features

FeatureImplementation
Access ControlonlyValidator modifier
Reentrancy ProtectionReentrancyGuard + CEI pattern
Double CertificationnotCertified modifier
Soulbound NFTDisabled transfer functions
Ban SystemOn-chain failed attempts tracking
Input Validationrequire() with descriptive messages

📊 Smart Contract Details

PropertyValue
NetworkEthereum Sepolia Testnet
Contract Address0x7297C08190DC726ce1fbDC62F14336Ae090a3aA6
Token StandardERC-721 Soulbound
Minimum Score60%
Maximum Attempts3
ValidatorDeployer Address

🧪 Test Coverage

TestDescriptionStatus
Happy PathValid student passes and receives NFT
Score Below MinimumTransaction reverts if score < 60
Max Attempts ExceededTransaction reverts if attempts > 3
Unauthorized AccessNon-validator call reverts

🤖 AI Model Details

Model: K-Nearest Neighbors (KNN) Features: [score, attempts, completion_time] Training Samples: 60 samples (12 per class) Classes: Excellent / Good / Pass / Weak Pass / Fail Normalization: MinMaxScaler


📜 License

MIT License


👤 Author

Manal Mahmoud Shahd Ibrahim

About

EduChain is a secure decentralized examination and certification platform built on Ethereum Sepolia. The system allows students to pay an on-chain exam fee, complete blockchain-based assessments, and receive Soulbound NFT certificates after passing.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages