This is the single local setup guide for the full Decentrocast project. Use it to install the backend and frontend, run tests, deploy locally, connect MetaMask, and use the app.
- Node.js 18+ and npm
- Git
- MetaMask browser extension
Check your versions:
node -v
npm -vgit clone <GITHUB_REPOSITORY_URL>
cd vite-voting-dappIf you use PowerShell and your folder path contains square brackets like [dev], use Set-Location -LiteralPath instead of cd.
backend-hardhat: Hardhat, Solidity contracts, deployment scripts, testsfrontend-vite: React + Vite frontend
Install backend dependencies:
cd backend-hardhat
npm installInstall frontend dependencies in a separate terminal, or after backend install completes:
cd frontend-vite
npm installFrom backend-hardhat:
npm run compileThis compiles the Solidity contract from contracts/ and updates Hardhat artifacts.
From backend-hardhat:
npm testThis runs the Hardhat test suite on the in-memory network.
The latest saved backend test log is here:
backend-hardhat/test-logs/latest.log
Open Terminal 1 and run:
cd backend-hardhat
npm run nodeKeep this terminal running.
This starts the local blockchain at http://127.0.0.1:8545 with chain ID 31337.
Open Terminal 2 and run:
cd backend-hardhat
npm run deploy:localhostEquivalent command:
npx hardhat run scripts/deploy.js --network localhostExpected output includes:
- Contract name
- Network and chain ID
- Deployer address
- Deployment transaction hash
- Contract address
- Voting window details
- Gas and total deployment cost
Copy the deployed contract address from the terminal output.
Open frontend-vite/src/constants/constant.js and replace the current contract address value with the address from the localhost deployment.
Update this line:
const contractAddress = "0x...";Do not change the ABI import unless the contract path changes.
Open Terminal 3 and run:
cd frontend-vite
npm run devOpen the local URL shown by Vite, usually:
http://localhost:5173/
Add the local Hardhat network to MetaMask:
- Network Name:
Localhost 8545 - RPC URL:
http://127.0.0.1:8545 - Chain ID:
31337 - Currency Symbol:
ETH(optional)
Then:
- Copy one of the private keys printed by
npm run nodein Terminal 1. - Import that account into MetaMask.
- Switch MetaMask to the
Localhost 8545network. - Connect the wallet to the frontend.
- Click
Connect MetaMask Wallet. - Approve the wallet connection.
- Review the candidate list shown in the UI.
- Enter the candidate index you want to vote for.
- Submit the vote and confirm the MetaMask transaction.
- Wait for the transaction to be mined and the UI to refresh.
From backend-hardhat:
npm run clean: clears Hardhat build outputsnpm run deploy: deploys to the default in-memory Hardhat network for that command onlynpm run test:log: runs tests and writes the output to the backend test log
Create backend-hardhat/.env only if you want to deploy to Sepolia or enable gas reporting.
Example:
SEPOLIA_ALCHEMY_RPC_URL=
METAMASK_PRIVATE_KEY=
ETHERSCAN_API_KEY=
COINMARKETCAP_API_KEY=
REPORT_GAS_USAGE=falseNotes:
- Do not commit real private keys.
- Localhost development does not require these values.
Deploy to Sepolia with:
cd backend-hardhat
npx hardhat run scripts/deploy.js --network sepolia