Ropsten (Ethereum) smart contract integration using Metamask, Ethers, React and Material UI v5
A survey company wants to make a new quiz form that rewards users with tokens for participating in the survey. They create surveys, loading them into JSON format and they want you to program a responsive web application using React or Next.js & Material UI/AntDesign for people to answer and submit they results, getting tokens in the process.
The web should behave as follows:
- Connect Metamask wallet.
- Ensure the user is connected to
Ropsten Testnet
and if not connected show a button to switch networks automatically. - Show the current balance of
$QUIZ
token (address below). - Once the page is loaded, present the title of the daily trivia with its picture and a button that allows you to begin answering.
- Once the survey starts, display the current question, which will be available for
the amount of seconds in the
lifetimeSeconds
property. - Answered or not it should move onto the next question.
- Once all the questions are finished, show an overview with all the answers.
- Show a button to submit the questions to the validator contract
- Refresh the balance of
$QUIZ
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
1 . Clone this repository or unzip the .zip file.
2 . Create an .env
file following .env.example
file.
3 . Install dependencies using:
$ yarn
4 . (Optional) Run existent tests with:
$ yarn test
3 . Run the development server with:
$ yarn start
4 . Make sure to install Metamask on your browser.
5 . Get some Ropsten ETH (rETH)
from a faucet like this one
Here are some screenshots of the app working. You can tell about the project structure just by looking at the user flow.
- ReactJs - Web UI Library
- Material UI - UI Component & Styles Library
- Ethers - Web3 Convenience Library
- Sentry - Error Reporting Toolkit
-
The application is live on
Heroku
. The latest version of themain
can be found running here. -
Due to the challenge description not providing an actual API to fetch the
Daily Trivia
the sample JSON was served from the/public
directory. Nevertheless, it is possible to change the URL and point to an actual API just by changing the variableREACT_APP_SURVEY_URL
on the.env
file. -
If any Sentry errors are seen in the console output, know this happens because you probably have an ad blocker of some sort installed as a browser extension.
Here is a list with some improvements that could make both the user and developer experience better:
1 . Write the rest of the missing tests to help avoid unwanted state mutations and ensure a proper user flow.
2 . Extract re-usable logic from contexts and common components into custom hooks if deemed necessary.
3 . Improve error handling by typing and capturing Ethers.js errors such as replaced transactions, failed transactions, reverted transactions and transactions rejected by the user. Enumerate these in an enum structure or object of some sort.