{"id":23812981,"url":"https://github.com/devashishdxt/substrate-voting-contract","last_synced_at":"2026-06-19T08:02:33.178Z","repository":{"id":189846536,"uuid":"681422579","full_name":"devashishdxt/substrate-voting-contract","owner":"devashishdxt","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-22T01:43:30.000Z","size":493,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-01T04:32:12.038Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devashishdxt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-22T01:41:17.000Z","updated_at":"2023-08-22T01:42:02.000Z","dependencies_parsed_at":"2023-08-22T03:26:15.481Z","dependency_job_id":null,"html_url":"https://github.com/devashishdxt/substrate-voting-contract","commit_stats":null,"previous_names":["devashishdxt/substrate-voting-contract"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devashishdxt/substrate-voting-contract","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devashishdxt%2Fsubstrate-voting-contract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devashishdxt%2Fsubstrate-voting-contract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devashishdxt%2Fsubstrate-voting-contract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devashishdxt%2Fsubstrate-voting-contract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devashishdxt","download_url":"https://codeload.github.com/devashishdxt/substrate-voting-contract/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devashishdxt%2Fsubstrate-voting-contract/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34522042,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-02T02:39:18.243Z","updated_at":"2026-06-19T08:02:33.129Z","avatar_url":"https://github.com/devashishdxt.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Voting Smart Contract\n\nThis repository contains code for a voting smart contract that allows users to create a poll and vote on it. The smart\ncontract is written using [ink!](https://use.ink/). **ink!** smart contracts are written in\n[Rust](https://www.rust-lang.org/) and are compiled to WebAssembly before being deployed on the blockchain.\n\n## Getting Started\n\n### Prerequisites\n\nBefore you can run the smart contract, you need to install all the prerequisites for running substrate. You can find the\ndetailed instructions for installing the prerequisites [here](https://docs.substrate.io/install/).\n\nIn addition to the substrate prerequisites, you also need to install ink! CLI. You can find the detailed instructions\n[here](https://github.com/paritytech/cargo-contract#installation).\n\nFor building and running different components, you need to install the\n[just](https://just.systems/man/en/chapter_4.html) and [jql](https://github.com/yamafaktory/jql#-installation).\n\n\u003e Note that **just** and **jql** are not required for running the dapp. You can alternatively run the individual\ncommands manually. However, **just** and **jql** make it easier to run these commands.\n\n### Building\n\nTo build all the components, run the following command:\n\n```bash\njust build\n```\n\n\u003e Note that this might take some time if you're building the substrate node for the first time.\n\n### Testing\n\nTo run the tests for all the components, run the following command:\n\n```bash\njust test\n```\n\n### Running\n\nTo run a local substrate node, run the following command:\n\n```bash\njust run-substrate-node\n```\n\nIn a separate terminal, run the following command to deploy the smart contract on the local substrate node:\n\n```bash\njust deploy-voting-contract\n```\n\n#### Troubleshooting\n\nIf you get an error while deploying the smart contract, try purging the local substrate node before deploying the smart\ncontract:\n\n```bash\njust purge-substrate-node\n```\n\n### Upgrading\n\nVoting smart contract intentionally introduces a bug where it does not compute the winner of a poll. This bug is fixed\nin the upgraded version of voting smart contract (to demonstrate the upgrade functionality).\n\nTo upgrade the smart contract, run the following command:\n\n```bash\njust upgrade-voting-contract\n```\n\nOnce the smart contract is upgraded, it should correctly report the winners of all the future polls.\n\n### Usage\n\nAfter running the node and deploying the smart contract, you can interact with the smart contract using\n[https://contracts-ui.substrate.io/](https://contracts-ui.substrate.io/).\n\nTo add the smart contract to `Contracts UI`, select the `Add New Contract` tab and `Use On-Chain Contract Address`\noption on Contracts UI.\n\n\u003e Note that Contracts UI, sometimes, does not register keyboard inputs on ID fields (e.g. poll ID, choice ID, etc.). The\n  ID fields can be changed using up and down arrow keys. \n\n![Voting Contract 1](./images/Add%20Contract%201.png)\n\nNext, copy the deployed contract address from `instantiated-voting-contract.json` (which is created during deployment).\n\n![Voting Contract 2](./images/Add%20Contract%202.png)\n\nFinally, paste the contract address in the `Contract Address` field and follow on-screen instructions. You'll also have\nto upload contract's ABI which can be found in `contracts/voting_contract/target/ink/voting_contract.json`.\n\n![Voting Contract 3](./images/Add%20Contract%203.png)\n\n1. **Creating a poll**\n\n   To create a new poll, select the `createPoll` function and enter the poll ID and description and call the contract.\n\n   ![Create Poll](./images/Create%20Poll.png)\n\n   Once the poll is created, you should see the generated event in `Transaction log` on the UI.\n\n2. **Add a choice to poll**\n\n   To add choices to a poll, select the `addChoice` function and enter the poll ID, choice ID and choice description and\n   call the contract.\n\n   ![Add Choice](./images/Add%20Choice.png)\n\n   You can add multiple choices to a poll.\n\n3. **Start a poll**\n\n   Once all the choices are added to a poll, you can start the poll by selecting the `startPoll` function and entering\n   the poll ID and calling the contract.\n\n   ![Start Poll](./images/Start%20Poll.png)\n\n4. **Vote on a poll**\n\n   To vote on a poll, select the `vote` function and enter the poll ID and choice ID and call the contract.\n\n   ![Vote](./images/Vote.png)\n\n   Multiple users can vote on a poll but one user can only vote once. To add multiple votes, change the `Caller` on\n   Contracts UI before calling the `vote` function again.\n\n5. **End a poll**\n\n   Once all the users have voted on a poll, you can end the poll by selecting the `endPoll` function and entering the\n   poll ID and calling the contract.\n    \n   ![End Poll](./images/End%20Poll.png)\n\n6. **Get poll results**\n\n   To get the results of a poll, select the `getReport` function and enter the poll ID and calling the contract. The\n   results of the poll will be displayed in the `Outcome` section of the UI.\n    \n   ![Get Report](./images/Get%20Report.png)\n\n   Notice that the contract does not report the winner of the poll. This is because the contract has a intentional bug\n   where it skips winner calculation. This bug is fixed in the upgraded version of the contract.\n\nNext, you can follow the steps in `Upgrading` section of this document to upgrade the smart contract and then repeat the\nabove process. This time, the contract should correctly report the winner of the poll. Note that you'll have to add a\nnew contract to Contracts UI with the same contract address but upgraded version of the contract's ABI which can be\nfound in `contracts/upgraded_voting_contract/target/ink/upgraded_voting_contract.json`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevashishdxt%2Fsubstrate-voting-contract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevashishdxt%2Fsubstrate-voting-contract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevashishdxt%2Fsubstrate-voting-contract/lists"}