A decentralized voting application built on Solana using Anchor framework. Implements token-based voting where users purchase tokens with SOL, register proposals, and cast votes.
Program ID: 3tSg7dX3NRgNsCyFL4fGw6RWzjhWUUeSCvveBVaZ8PB5
Solana Blockchain
β
βββ Vote DApp Program (Anchor)
β βββ lib.rs (9 instruction handlers)
β βββ contexts.rs (Account validation)
β βββ state.rs (Data structures)
β βββ errors.rs (Error handling)
β βββ events.rs (Event emissions)
β
βββ External Programs (via CPI)
βββ System Program (SOL transfers)
βββ Token Program (SPL tokens)
βββ Associated Token Program
treasury_config- Treasury configurationx_mint- Voting token mintsol_vault- Receives SOL from purchasesproposal_{id}- One per proposalvoter_{pubkey}- One per votervote_{pubkey}_{id}- One per votewinner- Winning proposal tracker
vote_dapp/
βββ programs/vote_dapp/src/
β βββ lib.rs # Instruction handlers
β βββ contexts.rs # Account contexts
β βββ state.rs # On-chain data
β βββ errors.rs # Custom errors
β βββ events.rs # Events
βββ tests/
β βββ vote_dapp.ts # Test suite
βββ Anchor.toml # Config
- Token Purchase - Buy voting tokens with SOL
- Voter Registration - Register as eligible voter
- Proposal Creation - Create proposals with token deposit
- Voting - Cast yes/no votes with token commitment
- Winner Selection - Automatic winner after deadline
- Account Management - Rent recovery via account closure
Used for SOL transfers and token operations:
system_program::transfer(cpi_context, amount)?;
transfer(transfer_ctx, token_amount)?;Deterministic accounts without private keys:
// Single instance
seeds = [b"treasury_config"], bump
// Per-user
seeds = [b"voter", authority.key().as_ref()], bump
// Per-entity
seeds = [b"proposal", proposal_id.to_le_bytes().as_ref()], bumpDeclarative security checks:
constraint=treasury_config_account.x_mint == x_mint.key()
constraint=authority.key() == treasury_config_account.authority @ VoteError::UnauthorizedAccessPDAs need signer seeds when signing transactions:
let signer_seeds = &[&[b"sol_vault", &[bump]][..]];
CpiContext::new_with_signer(program, accounts, signer_seeds)Different patterns for different needs:
init- Always creates new accountinit_if_needed- Creates only if doesn't exist- Manual checks - Custom validation logic
#[max_len(64)]
pub proposal_info: Stringproposal_count.checked_add(1)
.ok_or(VoteError::ProposalCounterOverflow)?;#[account(..., close = destination)]
pub proposal_account: Account<'info, Proposal>Authority β initialize() β Create PDAs β Treasury ready
Buyer β buy_tokens() β Transfer SOL β Mint tokens β Tokens received
Voter β register_voter() β proposal_to_vote() β Transfer tokens β Vote recorded
Authority β pick_winner() β Check deadline β Update winner account
- Solana Blockchain - High-performance blockchain
- Anchor Framework v0.32.1 - Solana development framework
- Rust - Program language
- SPL Token - Token standard
- TypeScript - Tests & client
- Rust, Solana CLI, Anchor CLI, Node.js
anchor build # Build program
anchor test # Run tests
anchor deploy # Deploy to localnet
This project demonstrates:
β
Solana Expertise - Anchor framework, PDAs, CPI patterns
β
Security - Validation, overflow protection, authority checks
β
Code Quality - Modular architecture, type safety
β
Testing - Comprehensive test coverage
Built with Anchor Framework on Solana