QuestionContract is a smart contract developed on the Ethereum blockchain using Solidity. It's designed to create and manage a simple quiz that users can interact with.
Aug 06, 2023
Unlicense
QuestionContract is a smart contract developed on the Ethereum blockchain using Solidity. It's designed to create and manage a simple quiz that users can interact with.
The contract is comprised of the following main elements:
Quiz: A struct representing a quiz, containing a question, an array of options, and the index of the correct answer.quiz: A public state variable of type Quiz.hasAnswered: A mapping that links Ethereum addresses with a boolean value, representing whether the associated address has answered the quiz.isCorrect: A similar mapping that associates Ethereum addresses with a boolean, indicating if the answer provided by that address was correct.constructor: Initializes the quiz with a question, options, and the correct answer index.answerQuestion: Allows an Ethereum address to answer the quiz. It updates the hasAnswered and isCorrect mappings based on the answer.getQuiz: Returns the question and its options.checkAnswer: Returns a boolean indicating whether the calling address has answered the quiz correctly.