Skip to content

Latest commit

Β 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—³οΈ Soroban Voting Smart Contract (Stellar)

A multiple-choice voting system implemented in Rust for the Stellar network using Soroban.

πŸš€ Features

  • βœ… Multiple-choice voting
  • βœ… Admin control for managing elections
  • βœ… Unique vote verification per address
  • βœ… Real-time results
  • βœ… Simple and intuitive interface

πŸ“‹ Prerequisites

  • Rust (version 1.70+)
  • Cargo
  • Soroban CLI
  • Stellar Testnet account

πŸ”§ Installation

1. Install Soroban CLI

cargo install --locked soroban-cli

2. Verify installation

soroban --version

πŸš€ Automated Deployment

Option 1: Automated Script (Recommended)

# Make executable
chmod +x deploy.sh

# Execute deployment
./deploy.sh

Option 2: Manual Deployment

Step 1: Compile

cargo build --target wasm32-unknown-unknown --release

Step 2: Optimize WASM

soroban contract optimize --wasm target/wasm32-unknown-unknown/release/voting.wasm

Step 3: Configure Identity

soroban keys generate alice

Step 4: Configure Testnet Network

soroban network add testnet \
  --rpc-url https://soroban-testnet.stellar.org:443 \
  --network-passphrase "Test SDF Network ; September 2015"

Step 5: Deploy

soroban contract deploy \
  --wasm target/wasm32-unknown-unknown/release/voting.wasm \
  --source alice \
  --network testnet

Step 6: Initialize

# Replace [CONTRACT_ID] with the ID returned from deployment
soroban contract invoke \
  --id [CONTRACT_ID] \
  --source alice \
  --network testnet \
  -- initialize \
  --admin [ADMIN_ADDRESS]

πŸ“– How to Use

1. Create Election

soroban contract invoke \
  --id [CONTRACT_ID] \
  --source alice \
  --network testnet \
  -- create_election \
  --title "Presidential Election 2024" \
  --description "Presidential voting" \
  --end_time 1735689600

2. Add Candidates

soroban contract invoke \
  --id [CONTRACT_ID] \
  --source alice \
  --network testnet \
  -- add_party \
  --name "Candidate A" \
  --description "Liberal Party"

3. Vote

soroban contract invoke \
  --id [CONTRACT_ID] \
  --source [VOTER_ADDRESS] \
  --network testnet \
  -- vote \
  --election_id 0 \
  --party_id 0

4. View Results

soroban contract invoke \
  --id [CONTRACT_ID] \
  --source alice \
  --network testnet \
  -- get_results \
  --election_id 0

πŸ” Contract Structure

Main Functions

  • initialize(admin: Address) - Initialize the contract
  • create_election(title: String, description: String, end_time: u64) - Create new election
  • add_party(name: String, description: String) - Add candidate/party
  • vote(election_id: u32, party_id: u32) - Cast vote
  • get_results(election_id: u32) - Get election results

Data Structures

  • Election - Election information
  • Party - Candidate/party information
  • Vote - Individual vote record

🌐 Available Networks

Testnet

Mainnet (Production)

πŸ’° Funding (Testnet)

To obtain XLM on testnet:

πŸ› Troubleshooting

Error: "stellar contract optimize"

  • Problem: Incorrect command
  • Solution: Use soroban contract optimize

Error: "No such file or directory"

  • Problem: Incorrect WASM path
  • Solution: Verify the file is at target/wasm32-unknown-unknown/release/voting.wasm

Error: "Soroban CLI not found"

  • Problem: CLI not installed
  • Solution: Run cargo install --locked soroban-cli

πŸ“š Additional Resources

🀝 Contributing

  1. Fork the project
  2. Create a 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 more details.

πŸ†˜ Support

If you encounter problems:

  1. Check error logs
  2. Consult the documentation
  3. Open an issue on GitHub
  4. Contact the development team

Developed with ❀️ for the Stellar community

About

● πŸ—³οΈ Stellar Soroban Voting Smart Contract - Decentralized system with vote delegation, admin control, double-vote prevention and real-time results. Built in Rust for Stellar blockchain with automated testnet deployment.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages