Smart contracts for the HackSP hackathon voting system.
This repository is part of a project created for the HackSP community, a community made by and for high school students in Sao Paulo. The goal of this application is to run hackathon voting with Web3 infrastructure so the process is more transparent, auditable, and harder to manipulate.
Hackathons need trust.
When participants, mentors, and organizers look at the final results, they should be able to understand that:
- the voting rules were defined in code
- each allowed wallet can vote only once
- votes are stored on-chain
- the final result can be checked publicly
Using a smart contract does not replace good event organization, but it gives HackSP a transparent voting layer that the community can inspect.
The main contract is contracts/HackathonVoting.sol.
It allows the contract owner to:
- create a new hackathon
- add projects to that hackathon
- register voter wallets
- define the voter role
- open and close the voting period
It allows registered wallets to:
- vote once in a specific hackathon
It also provides read functions to:
- check project vote totals
- check whether a wallet has already voted
- check whether a wallet is allowed to vote
- check how many projects exist in a hackathon
The contract currently uses two voter roles:
Team: vote weight =1Mentor: vote weight =3
This means mentors have a higher voting weight than team members. Every registered wallet can vote only one time per hackathon.
contracts/HackathonVoting.sol: main smart contractscripts/deploy.ts: deployment scripttest/test.ts: integration-style test scripthardhat.config.ts: Hardhat network configurationdeployments.json: deployed contract addresses by environment.env.sample: environment variable template
This project loads environment variables from files named:
.env.local.env.dev.env.prod
The file used depends on the ENV value passed to the scripts.
Use .env.sample as the base template:
RPC_URL=http://127.0.0.1:8545
PRIVATE_KEY=0xYOUR_PRIVATE_KEY
CHAIN_ID=31337
CHAIN_TYPE=l1
ENV=local
CONTRACT_NAME=HackathonVotingCreate the environment files by copying the sample and adjusting the values for each network.
Example:
cp .env.sample .env.local
cp .env.sample .env.dev
cp .env.sample .env.prodRPC_URL: blockchain RPC endpoint used by Hardhat, deployment scripts, and testsPRIVATE_KEY: wallet private key used to deploy and interact with the contractCHAIN_ID: numeric chain identifier for the target networkCHAIN_TYPE: Hardhat chain type, currently expected asl1oropENV: selects which environment file and deployment namespace to useCONTRACT_NAME: contract name to deploy, currentlyHackathonVoting
We create separate environment files so the same codebase can be used safely in different contexts:
local: local development with a local Hardhat nodedev: test environment, useful for staging or testnet deploymentsprod: production environment for the real deployed contract
This separation helps avoid mistakes such as:
- deploying to the wrong network
- using the wrong private key
- overwriting the wrong deployment record
- testing against production settings
Install dependencies:
npm installOr:
yarn installStart a local blockchain:
npm run chainIn another terminal, deploy the contract locally:
npm run deploy:localRun the local test script:
npm run test:localnpm run chain: starts a local Hardhat nodenpm run deploy:local: deploys using.env.localnpm run deploy:dev: deploys using.env.devnpm run deploy:prod: deploys using.env.prodnpm run test:local: runs the test script against the local environmentnpm run test:dev: runs the test script against the development environment
- Configure the correct
.env.<environment>file. - Run the deploy script for that environment.
- The contract address is saved to
deployments.json. - The test script reads that address and interacts with the deployed contract.
To make the system more transparent, the deployed contract addresses are published in this README based on deployments.json.
This section is generated from deployments.json.
| Environment | Network | Contract | Address | Explorer |
|---|---|---|---|---|
local |
Local Hardhat | HackathonVoting |
0x5fbdb2315678afecb367f032d93f642f64180aa3 |
Not public |
dev |
Base Sepolia | HackathonVoting |
0x713a96a263da1b5330e385f5ddd80a52e15119dd |
View on BaseScan |
prod |
Base Mainnet | HackathonVoting |
0x03c1ba0e11ed7f4da68beda1d19b0c0028908a73 |
View on BaseScan |
Run npm run readme:addresses after each deployment to refresh this table.
This gives organizers, participants, and the community a clear place to verify which contract is being used in each environment and inspect the deployed contract directly on Base.
Because this system is on-chain, HackSP can offer:
- public and verifiable vote storage
- clear voting rules enforced by the contract
- visible contract addresses for each environment
- visible deployment history per environment
- easier auditing by organizers, participants, and community members
- only the contract owner can create hackathons, add projects, register voters, and open or close voting
- the current test script blocks execution in
prod - mentor votes currently have more weight than team votes by design
HackSP is a community made by and for high school students in Sao Paulo. This project exists to support fairer, clearer, and more trustworthy hackathon operations for that community.