Skip to content

gconnect/voting-dapp-pyteal-react

Repository files navigation

Building and Deploying a Decentralised Voting System with PyTeal and React

Frame 27

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 Smart Contract

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

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

Frontend Interactions with React

To interact with the application the UI code can be found in src/components

AlgoSigner

  • The AlgoSigner will be used for signing the transactions on the demo app.

Deploy Smart Contract with the Algorand JavaScript SDK

The JavaScript SDK will be used for deploying the smart contract code.

Setup Requirements

Run the Code

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 do npm install again)
  • run npm start to start the local server at localhost:3000

Demo

Screenshot 2022-03-16 at 03 14 24

Here is a demo link to the deployed Application on vercel.

License

Distributed under the MIT License. See for more information. LICENSE

Blog and Video Tutorial

For more details you can checkout the blog post here . And here is the link to the youtube demo

Disclaimer

Warning

This project is not audited and should not be used in a production environment.

About

Decentralized Voting System with PyTeal and React

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages