Skip to content

A decentralized voting application built on the Stacks blockchain using Clarity 4 smart contracts.

License

Notifications You must be signed in to change notification settings

LFGBanditLabs/stacksvote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

70 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—³οΈ StacksVote

A decentralized voting platform built on Stacks blockchain with Clarity 4 smart contracts and Next.js

License: MIT Stacks Next.js Clarity Deploy with Vercel

🎯 Live Demo

View Live Application β†’

Contract Address: SP1C5DP9C9N2MB8DMZN18EJNSSA3GYNJE3DGN806V.voting

✨ Features

Smart Contract (Clarity 4)

  • πŸ“ 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

Frontend (Next.js 15)

  • 🎨 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

πŸš€ Quick Start

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/LFGBanditLabs/stacksvote.git
    cd stacksvote
  2. Install frontend dependencies

    cd voting-frontend
    npm install
  3. Start development server

    npm run dev
  4. Open your browser

    http://localhost:3000
    

πŸ“‚ Project Structure

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

πŸ”§ Smart Contract

Public Functions

create-proposal

(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

(cast-vote (proposal-id uint) (vote-choice bool))

Vote on a proposal. true = Yes, false = No. Uses voter's weight.

set-voter-weight

(set-voter-weight (voter principal) (weight uint))

Set voting weight for a user (owner only). Default weight is 1.

execute-proposal

(execute-proposal (proposal-id uint))

Mark proposal as executed after voting period ends.

Read-only Functions

  • get-proposal(proposal-id) - Retrieve proposal details
  • get-proposal-count() - Total number of proposals
  • is-proposal-active(proposal-id) - Check if voting is active
  • get-proposal-result(proposal-id) - Get voting results
  • get-voter-weight(voter) - Get user's voting weight
  • get-vote(proposal-id, voter) - Get specific vote details

🌐 Deployment

Deploy Smart Contract

  1. Configure deployment

    cd counter
    cp settings/Mainnet.toml.example settings/Mainnet.toml
    # Add your mnemonic to Mainnet.toml
  2. Generate deployment plan

    clarinet deployments generate --mainnet
  3. Deploy to mainnet

    clarinet deployments apply --mainnet

Deploy Frontend (Vercel)

Deploy with Vercel

Or manually:

cd voting-frontend
npm run build
npm start

πŸ§ͺ Testing

Smart Contract Tests

cd counter
npm test

Frontend Development

cd voting-frontend
npm run dev

🎯 Usage

Creating a Proposal

  1. Connect your Stacks wallet
  2. Click "Create New Proposal"
  3. Fill in:
    • Title: Short proposal name
    • Description: Detailed explanation
    • Duration: Voting period (in blocks)
  4. Submit and confirm transaction

Voting on Proposals

  1. Browse active proposals on homepage
  2. Click "Vote Yes" or "Vote No"
  3. Confirm transaction in wallet
  4. Vote is recorded on-chain

Viewing Results

  • Progress bars show current vote distribution
  • Total votes displayed for each option
  • Proposal status indicates if voting is active

πŸ› οΈ Configuration

Update Contract Address

Edit voting-frontend/lib/constants.ts:

export const CONTRACT_ADDRESS = 'YOUR_CONTRACT_ADDRESS';
export const CONTRACT_NAME = 'voting';
export const NETWORK = 'mainnet'; // or 'testnet'

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments


πŸ“ž Support


Made with ❀️ by LFGBanditLabs

⭐ Star this repo if you find it useful!

About

A decentralized voting application built on the Stacks blockchain using Clarity 4 smart contracts.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published