You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A decentralized voting application built on Ethereum. Create drafts, vote with yeas/nays, and when a draft reaches 5 yeas, it automatically becomes a proposition on-chain.
cd blockchain
# Install dependencies
npm install
# Create environment file
cp .env.example .env
# Edit .env with your private key (for deployment only)# Start local blockchain
npm run node
2. Deploy Contract (new terminal)
cd blockchain
# Deploy to local network
npm run deploy:local
# OR deploy to Sepolia testnet
npm run deploy:sepolia
# OR deploy to Polygon Amoy testnet
npm run deploy:amoy
This will:
Deploy the contract
Save deployment info to deployments/[network].json
Copy ABI to frontend/src/contracts/
3. Setup Frontend
cd frontend
# Install dependencies
npm install
# Start development server
npm run dev
4. Connect MetaMask
Open MetaMask
For local development: Add network with RPC URL http://127.0.0.1:8545 and Chain ID 31337
Import a test account using private key from Hardhat node output
Connect to the app
Smart Contract
Functions
Function
Description
createDraft(content)
Create a new draft
yeaDraft(draftId)
Vote yea on a draft
nayDraft(draftId)
Vote nay on a draft
deleteDraft(draftId)
Delete your draft
yeaProp(propId)
Vote yea on a proposition
nayProp(propId)
Vote nay on a proposition
deleteProp(propId)
Delete your proposition
Events
Event
Description
DraftCreated
Emitted when a draft is created
DraftVoted
Emitted when someone votes on a draft
DraftPromoted
Emitted when a draft becomes a proposition
PropositionCreated
Emitted when a proposition is created
PropositionVoted
Emitted when someone votes on a proposition
Business Logic
Drafts start with 0 yeas and 0 nays
Each address can only vote once per draft/proposition
When a draft reaches 5 yeas, it automatically becomes a Proposition
Propositions start with 5 yeas
Only the author can delete their drafts/propositions
npm run compile # Compile contracts
npm run test# Run tests
npm run node # Start local blockchain
npm run deploy:local # Deploy to localhost
npm run deploy:sepolia # Deploy to Sepolia
Frontend
npm run dev # Start dev server
npm run build # Production build
npm run preview # Preview production
Security Considerations
Private keys should never be committed to version control
The contract uses simple access control (author-only delete)
One vote per address is enforced on-chain
Consider adding additional security features for production