A decentralized voting platform built on Stacks blockchain with Clarity 4 smart contracts and Next.js
Contract Address: SP1C5DP9C9N2MB8DMZN18EJNSSA3GYNJE3DGN806V.voting
- π Create Proposals - Anyone can submit proposals with title, description, and voting period
- π³οΈ Weighted Voting - Cast votes with customizable voting weights
- βοΈ Fair Governance - Transparent, on-chain voting mechanism
- β° Time-based Voting - Proposals have defined start and end blocks
- π Immutable Results - All votes permanently recorded on blockchain
- β Proposal Execution - Execute passed proposals after voting ends
- π¨ Modern, glassmorphic UI design
- π Seamless wallet integration (Hiro/Leather)
- π± Fully responsive mobile-first design
- β‘ Real-time proposal updates
- π Beautiful gradient animations
- π Automatic vote counting and progress tracking
- Node.js 18+
- npm or yarn
- Hiro Wallet or Leather Wallet
- Clarinet (for deployment)
-
Clone the repository
git clone https://github.com/LFGBanditLabs/stacksvote.git cd stacksvote -
Install frontend dependencies
cd voting-frontend npm install -
Start development server
npm run dev
-
Open your browser
http://localhost:3000
stacksvote/
βββ counter/ # Clarity smart contract project
β βββ contracts/
β β βββ voting.clar # Main voting contract
β βββ tests/
β β βββ voting.test.ts # Contract tests
β βββ settings/
β β βββ Mainnet.toml # Deployment configuration
β βββ Clarinet.toml # Clarinet project config
β
βββ voting-frontend/ # Next.js frontend application
βββ app/
β βββ page.tsx # Homepage
β βββ create/
β β βββ page.tsx # Create proposal page
β βββ layout.tsx # Root layout
βββ components/
β βββ Header.tsx # Navigation header
β βββ ProposalCard.tsx # Proposal display component
β βββ ProposalList.tsx # Proposal listing
βββ contexts/
β βββ AuthContext.tsx # Wallet authentication
βββ lib/
β βββ stacks.ts # Blockchain interactions
β βββ constants.ts # App configuration
βββ package.json
(create-proposal (title (string-utf8 256))
(description (string-utf8 1024))
(duration uint))Create a new proposal with voting duration in blocks (~10 minutes per 100 blocks).
(cast-vote (proposal-id uint) (vote-choice bool))Vote on a proposal. true = Yes, false = No. Uses voter's weight.
(set-voter-weight (voter principal) (weight uint))Set voting weight for a user (owner only). Default weight is 1.
(execute-proposal (proposal-id uint))Mark proposal as executed after voting period ends.
get-proposal(proposal-id)- Retrieve proposal detailsget-proposal-count()- Total number of proposalsis-proposal-active(proposal-id)- Check if voting is activeget-proposal-result(proposal-id)- Get voting resultsget-voter-weight(voter)- Get user's voting weightget-vote(proposal-id, voter)- Get specific vote details
-
Configure deployment
cd counter cp settings/Mainnet.toml.example settings/Mainnet.toml # Add your mnemonic to Mainnet.toml
-
Generate deployment plan
clarinet deployments generate --mainnet
-
Deploy to mainnet
clarinet deployments apply --mainnet
Or manually:
cd voting-frontend
npm run build
npm startcd counter
npm testcd voting-frontend
npm run dev- Connect your Stacks wallet
- Click "Create New Proposal"
- Fill in:
- Title: Short proposal name
- Description: Detailed explanation
- Duration: Voting period (in blocks)
- Submit and confirm transaction
- Browse active proposals on homepage
- Click "Vote Yes" or "Vote No"
- Confirm transaction in wallet
- Vote is recorded on-chain
- Progress bars show current vote distribution
- Total votes displayed for each option
- Proposal status indicates if voting is active
Edit voting-frontend/lib/constants.ts:
export const CONTRACT_ADDRESS = 'YOUR_CONTRACT_ADDRESS';
export const CONTRACT_NAME = 'voting';
export const NETWORK = 'mainnet'; // or 'testnet'Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Stacks
- Frontend powered by Next.js
- Smart contracts in Clarity
- UI styled with Tailwind CSS
- Wallet integration via @stacks/connect
- GitHub Issues: Report bugs or request features
- Stacks Discord: Join the community
Made with β€οΈ by LFGBanditLabs
β Star this repo if you find it useful!