thirdweb

QuestionContract

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.

QuestionContract

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.

Structure of the Contract

The contract is comprised of the following main elements:

Data Structures

  • 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.

Functions

  • 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.

Answer Question

(answerQuestion)

nonpayable

Inputs

_answerIndex

uint256

Published by

View all contracts

Details

  • Publish Date

    Aug 06, 2023

  • License

    Unlicense

  • Learn more about Publish