Read this in other languages: English , 日本語 .
Implement a questionnaire system using a smart contract.
- The questionnaire consists of questions and options and sets the response period (start and end).
- You can set the start and end date and time for voting. (1 minute minimum voting period)
- Anyone can answer the questionnaire, and can answer only once for each EOA address.
- The situation of the answer is always public.
- Since the content of the questionnaire is hashed and managed, the exact same content can not be created
Because information is recorded in the block chain, there is no concern such as falsification of the record
argument
- The contents of the string
_contents
questionnaire (the format is described below) - uint
_numberOfChoices
Choices - uint
_voteStartAt
Start timestamp for accepting answers - uint
_voteEndAt
Time stamp for closing answer
{
"question": "What is your favorite drink?",
"options": ["tea", "coffee", "orange juice", "cola"]
}
Javascript example:
const data = {
question: "What's your favorite drink?",
options: ['tea', 'coffee', 'orange juice', 'cola'],
};
const _contents = JSON.stringify(data);
function
function create(string memory _contents, uint _numberOfChoices, uint _voteStartAt, uint _voteEndAt) public onlyOwner returns (bool) { ... }
argument
- bytes32
_id
Questionnaire ID - uint
_choice
Number of choices to vote (number starts with zero)
function
function vote(bytes32 _id, uint _choice) public acceptingVoting(_id) returns (bool) { ... }
argument
- bytes32
_id
Questionnaire ID
function
function getResult(bytes32 _id) public view returns (uint[] memory) { ... }
The implementation will be published on GitHub.