Code Monkey home page Code Monkey logo

kozanakyel / icp-rust-voting-dapp Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 20 KB

๐Ÿš€ Smart Contract for Decentralized Proposals on the Internet Computer ๐ŸŒ This Rust-based smart contract allows users to create, edit, vote on, and determine the status of proposals in a decentralized manner on the Internet Computer blockchain. It leverages the Candid interface description language and stable data structures robust functionality

Rust 100.00%
blockchain canister icp internet-computer rust smart-contracts voting

icp-rust-voting-dapp's Introduction

ICP Rust Bootcamp - Proposal/Vote System Canister

This project implements a simple proposal system smart contract on the Internet Computer blockchain. Users can create, edit, end, and vote on proposals, with a query function to determine the status of a proposal based on community votes.

Table of Contents

Overview

The smart contract is written in Rust and uses the Candid interface description language for interacting with the Internet Computer. It utilizes the ic_stable_structures library for stable data structures and memory management.

Features

  • Create, edit, end, and vote on proposals.
  • Query the details of a proposal.
  • Get the total count of proposals.
  • Determine the status of a proposal based on community votes.

Getting Started

To deploy and interact with the smart contract, follow these steps:

  1. Clone the repository.
  2. Install the necessary dependencies.
  3. Build and deploy the smart contract.

Usage

Describe how users can deploy the smart contract and interact with its functions.

Query Functions

get_proposal(key: u64) -> Option<Proposal>

Retrieve the details of a proposal based on the provided key.

get_proposal_count() -> u64

Get the total count of proposals.

get_proposal_status(key: u64) -> String

Determine the status of a proposal based on community votes.

Update Functions

create_proposal(key: u64, proposal: CreateProposal) -> Option<Proposal>

Create a new proposal.

edit_proposal(key: u64, proposal: CreateProposal) -> Result<(), VoteError>

Edit an existing proposal.

end_proposal(key: u64) -> Result<(), VoteError>

End an active proposal.

vote(key: u64, choice: VoteTypes) -> Result<(), VoteError>

Vote on a proposal.

Proposal Status

The get_proposal_status query function calculates the status of a proposal. It declares the proposal as 'Approved,' 'Rejected,' 'Passed,' or 'Undecided' based on the votes.

  • A proposal must have at least 5 votes to be eligible for evaluation.
  • A status is only assigned if it earns at least 50% of the votes.

Contributing

Describe how others can contribute to the project.

Run-deploy-test

If you want to start working on your project right away, you might want to try the following commands:

cd vote/
dfx help
dfx canister --help

Running the project locally

If you want to test your project locally, you can use the following commands:

# Starts the replica, running in the background
dfx start --background

# Deploys your canisters to the replica and generates your candid interface
dfx deploy

Once the job completes, your application will be available at http://localhost:4943?canisterId={asset_canister_id}.

If you have made changes to your backend canister, you can generate a new candid interface with

npm run generate

at any time. This is recommended before starting the frontend development server, and will be run automatically any time you run dfx deploy.

If you are making frontend changes, you can start a development server with

npm start

Which will start a server at http://localhost:8080, proxying API requests to the replica at port 4943.

Note on frontend environment variables

If you are hosting frontend code somewhere without using DFX, you may need to make one of the following adjustments to ensure your project does not fetch the root key in production:

  • setDFX_NETWORK to ic if you are using Webpack
  • use your own preferred method to replace process.env.DFX_NETWORK in the autogenerated declarations
    • Setting canisters -> {asset_canister_id} -> declarations -> env_override to a string in dfx.json will replace process.env.DFX_NETWORK with the string in the autogenerated declarations
  • Write your own createActor constructor

icp-rust-voting-dapp's People

Contributors

kozanakyel avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.