The business value of this tutorial is to teach how to write a smart contract code with PyTeal and Deploy using the Algorand JavaScript SDK and React on the Frontend to interact with the application.
The goal of the voting smart contract is to enable voters vote for their candidate of choice from a list of candidates.And the votes will be stored globally on the Algorand blockchain.
The voting system allows accounts to register and vote for arbitrary choices. Here a choice is any byte slice and anyone is allowed to register to vote.
This tutorial has a configurable registration period defined by the global state Registration Begin and Registration End which restrict when accounts can register to vote. There is also a separate configurable voting period defined by the global state Voting Begin and Voting End which restrict when voting can take place. But for the purpose of testing/demo the registration and voting period will be left open.
An account must register in order to vote. Accounts cannot vote more than once. The results are visible in the global state of the application, and the winner is the candidate with the highest number of votes.
PyTeal is a python library for generating TEAL programs that provides a convenient and familiar syntax.
This handles building of the smart contract with PyTeal. The smart contract code can be found in src/contract.py
TEAL is Transaction Execution Approval Language. PyTeal code will be compiled to TEAL. The TEAL code consist of the Approval Program and Clear State Program.
The Approval program can be found in src/contract/vote_approval.teal
and the Clear State Program can be found in src/contract/vote_clear_state.teal
To interact with the application the UI code can be found in src/components
- The AlgoSigner will be used for signing the transactions on the demo app.
The JavaScript SDK will be used for deploying the smart contract code.
- Algorand JavaScript SDK
- Vs Code or any IDE of your choice
- Node Package Manager
- Create React App . This creates a react boilerplate app.
- Styled Components
- Python 3.6 or higher
- Pyteal Installation
To test the code
- Fork the repository
- Do
npm install
this will install all required dependencies. (If you encounter any issue after doing this you can delete the node module folder and donpm install
again) - run
npm start
to start the local server at localhost:3000
Here is a demo link to the deployed Application on vercel.
Distributed under the MIT License. See for more information. LICENSE
For more details you can checkout the blog post here . And here is the link to the youtube demo
This project is not audited and should not be used in a production environment.