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.
- Overview
- Features
- Getting Started
- Usage
- Query Functions
- Update Functions
- Proposal Status
- Contributing
- Run-deploy-test
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.
- 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.
To deploy and interact with the smart contract, follow these steps:
- Clone the repository.
- Install the necessary dependencies.
- Build and deploy the smart contract.
Describe how users can deploy the smart contract and interact with its functions.
Retrieve the details of a proposal based on the provided key.
Get the total count of proposals.
Determine the status of a proposal based on community votes.
Create a new proposal.
Edit an existing proposal.
End an active proposal.
Vote on a proposal.
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.
Describe how others can contribute to the project.
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
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.
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:
- set
DFX_NETWORK
toic
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
indfx.json
will replaceprocess.env.DFX_NETWORK
with the string in the autogenerated declarations
- Setting
- Write your own
createActor
constructor