This project implements a basic exam system using a Solidity smart contract. It allows a teacher to add questions and correct answers to an exam, and students can submit their answers to get automatically graded. Students can also view all the stored questions at once.
-
Teacher Functions:
- Add questions to the exam with correct answers.
- Manage questions stored on the blockchain.
-
Student Functions:
- Submit answers for grading.
- View their scores.
- Retrieve all the exam questions at once.
Question: Represents a question in the exam. It contains:questionText: The text of the question.correctAnswer: The correct answer for the question.
scores: Stores the scores of students, mapped by their address.
questions: An array ofQuestionstructs to store all the exam questions.teacher: The address of the teacher who deployed the contract.
-
addQuestion(string memory questionText, string memory correctAnswer) public onlyTeacher:- Adds a new question with the corresponding correct answer.
- Can only be called by the teacher.
-
submitAnswers(string[] memory answers) public:- Submits the student's answers for grading.
- Compares the student's answers to the correct answers stored on the blockchain and calculates their score.
-
getScore() public view returns (uint):- Returns the score of the student calling the function.
-
getAllQuestions() public view returns (string[] memory):- Returns an array containing all the question texts in the exam.
- Solidity: The smart contract is written in Solidity (version
0.8.0or above). - Ethereum Wallet: To interact with the deployed contract, you'll need an Ethereum wallet like MetaMask.
- Ethereum Testnet: Deploy the contract on an Ethereum-compatible testnet like Rinkeby, Goerli, or Arbitrum testnet.
-
Open Remix IDE:
- Visit Remix IDE.
- Create a new file named
Exam.soland paste the provided Solidity code.
-
Compile the Contract:
- Navigate to the "Solidity Compiler" tab.
- Choose compiler version
0.8.0or higher. - Click "Compile Exam.sol".
-
Deploy the Contract:
- Go to the "Deploy & Run Transactions" tab.
- Select the
Examcontract from the dropdown. - Ensure that the environment is set to "Injected Web3" to connect to MetaMask.
- Click "Deploy" and confirm the transaction in MetaMask.
-
Access the Deployed Contract:
- Once deployed, locate the contract's interface under the "Deployed Contracts" section.
-
Add a Question:
- Use the
addQuestionfunction to add a new question. - Input the question text and correct answer, then click "transact".
Example:
questionText: "What is the time complexity of binary search?"correctAnswer: "O(log n)"
- Use the
-
Submit Answers:
- Students can submit their answers using the
submitAnswersfunction. - Provide an array of answers corresponding to the questions, then click "transact".
Example:
- If there are 3 questions, submit the answers as:
["O(log n)", "Linked List", "3.5"].
- Students can submit their answers using the
-
View Score:
- Students can view their score by calling the
getScorefunction.
- Students can view their score by calling the
- Get All Questions:
- Students can view all the stored questions by calling the
getAllQuestionsfunction. - This returns an array of all the question texts.
- Students can view all the stored questions by calling the
- The teacher deploys the contract and adds several questions.
- Students interact with the contract to view the questions, submit their answers, and view their scores.
Network: EDUCHAIN
- Contract Address: 0x2c53DAA191365e3BD007Bb70627232A43e9dB4c1
The vision for this project is to create a decentralized and transparent exam system where exam questions and grading are managed on the blockchain, ensuring integrity and accessibility.
- Enhanced Features: Integration of more advanced features like multiple-choice questions, timed exams, or automatic feedback.
- Scalability: Explore deployment on other Ethereum-compatible networks for broader accessibility.
- User Interface: Develop a user-friendly front-end application for easier interaction with the smart contract.
- Developer: Shahin Sha Alomgir
- Email: Shahinxsha@gmail.com
- GitHub: https://github.com/Nukeio
- Teacher Privileges: Only the teacher (contract deployer) can add questions.
- Answer Submission: Students can only submit their answers once, and all questions must be answered.
This Solidity smart contract provides a basic framework for an exam system on the blockchain. It is a simple yet effective way to demonstrate how decentralized exams can be implemented using smart contracts.

