Skip to content

Conversation

@ogazboiz
Copy link

Summary

This PR adds a complete Community Voting System that allows players to propose and vote on game improvements.

What's New

  • Smart Contract (voting.clar) - Proposal creation, voting, and management
  • 6 New Tests - Comprehensive test coverage (all passing)
  • Voting UI - New /voting page with proposal creation and voting interface
  • Wallet Integration - Transaction handling with @stacks/connect v8

Key Features

  1. Create Proposals - Community members can suggest game improvements
  2. Vote Yes/No - Cast votes on active proposals
  3. Double-Vote Prevention - Each wallet can only vote once per proposal
  4. Real-Time Results - Visual progress bars showing vote distribution
  5. Proposal Management - Owner can close proposals

Technical Implementation

Smart Contract (contracts/voting.clar)

  • Written in Clarity 3
  • Public functions: create-proposal, vote, close-proposal
  • Read-only functions: get-proposal, has-voted, get-proposal-count
  • Error handling with custom error codes

Tests (tests/voting.test.ts)

  • ✅ 16/16 tests passing (6 voting + 10 tic-tac-toe)
  • Tests cover: proposal creation, voting, double-vote prevention, proposal closure

Frontend

New Pages:

  • /voting - Main voting interface

New Components:

  • CreateProposal - Proposal creation form
  • ProposalsList - Displays proposals with voting UI

Updated Files:

  • frontend/lib/contract.ts - Added voting contract functions
  • frontend/hooks/use-stacks.ts - Added voting transaction handlers
  • frontend/components/navbar.tsx - Added "Voting" link

Deployment

  • Contract Address: STA43VC8660WWNRHHWSXGK2VR4BVHGWN0Z63FXGD.voting
  • Network: Stacks Testnet
  • Transaction ID: 0xf22faa4b4e8cb35e6aadf435c4ae39df2b1c0371f955942c020816657120fd8b

How to Test

Run Tests

npm run test
Expected: All 16 tests pass
Test Frontend
cd frontend
npm run dev
Visit http://localhost:3000/voting
Connect wallet
Create a proposal
Vote on the proposal
Try to vote again (should fail - double vote prevention)
Files Changed
New: contracts/voting.clar, tests/voting.test.ts, frontend/app/voting/page.tsx, 2 new components
Modified: frontend/lib/contract.ts, frontend/hooks/use-stacks.ts, frontend/components/navbar.tsx, Clarinet.toml
Why This Matters
This feature enables decentralized governance for the game, allowing the community to shape future development through on-chain voting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants