This section presents the Poll DApp example: users can create and answer polls. An account can only answer a poll once.
Poll definitions (question, image and possible answers) are stored on IPFS. The list of polls and user's answers are stored in a smart contract.
The DApp uses the MUI UI widget library.
Click the topbar
LOGIN button to connect to a wallet; select a wallet you want to connect to (Temple, Kukai, Umami, ...).
Once logged in, the login button is replaced by a panel with basic information:
- User address (
- Name of the wallet connected to
- Network (Ghostnet in this example)
- Endpoint (the Tezos endpoint the DApp using)
LOGOUTbutton to disconnet from wallet
Answer a poll
Steps to answer a poll:
- click on a poll in the DApp's main panel
- click on one of the possible answers
- click the
SUBMITbutton; it is then required to connect to a wallet (if not already logged in) and validate the transaction to the contract
Once the transaction is validated on the blockchain, the statistic of the poll (number of answers per possible answer) is displayed.
User is notified when another user either creates a new poll or answers a poll:
- a message is displayed at the bottom of the screen for a few seconds
- the detailed event information is added to the notification center
Create a poll
A poll is specified with a JSON file that defines the following fields:
utterance: the question asked by the poll (for example "What is your favorite food?")
img: a public URL to illustrate the question
choices: a list of choices
For example, below is the "What is your favorite food?" poll definition:
"utterance" : "What is your favorite food?",
"img" : "https://1.bp.blogspot.com/-WOrNura8t1g/W6ufizUlixI/AAAAAAAAA38/X05agj6atWcxyyaRgOl07jMeaZnuF7JwgCLcBGAs/w1200-h630-p-k-no-nu/World-Food-Day.jpg",
"choices" : [ "Pizza", "Burger", "Sushi", "Tacos", "Croissant" ]
The poll JSON file must be then uploaded to IPFS. The online app Pinata may be used for that. Once uploaded, the data is identified by a unique hash value.
For example, the hash of the above poll definition is
Steps to add a poll:
- click on the
ADD POLLbutton in the DApp's main panel
- paste the hash value in the IPFS hash field; the poll is then displayed for validation
- click the
SUBMITbutton; it is then required to connect to a wallet (if not already logged in) and validate the transaction to the contract.
Once submitted, the contract's owner (
tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P) needs to validate the poll for it to appear in the main panel.