How harsh242/betterfund-crowdfunding-in-blockchain works
Project Type and Purpose
• This is a full-stack decentralized application (dApp) for crowdfunding, built with Next.js (React) on the frontend, Solidity smart contracts on Ethereum (Rinkeby), and Web3.js for blockchain interactions.
• Users create and contribute to campaigns via a web UI; funds and campaign logic live on Ethereum smart contracts (CampaignFactory & Campaign).
File Structure Analysis
• Top-level directories:
• pages/ – Next.js pages (UI for listing, creating campaigns & requests, plus an API route)
• components/ – Reusable React components (Navbar, Footer, DarkModeSwitch)
• lib/ – Helper modules (e.g., getETHPrice.js for fetching ETH price)
• smart-contract/ – Solidity contracts, build artifacts, and Node scripts (compile.js, deploy.js, campaign.js, factory.js, web3.js)
• public/ – Static assets
• styles/ – CSS modules and globals
• Configuration & deployment: next.config.js, package.json, .env in smart-contract for Infura credentials.
README Insights
• Tech Stack: Next.js, Chakra UI, Solidity, Web3.js, deployed on Vercel & Rinkeby via Infura.
• Workflow:
a. compile.js → generates ABI JSONs
b. deploy.js → pushes contracts to Rinkeby, writes addresses into factory.js
c. Frontend uses web3.js + factory.js to instantiate Contract instances
• Rectangles for services/components
• Parallelograms for user interfaces
[Parallelogram: User Browser + MetaMask]
| (1) connect, sign tx
V
[Rectangle (blue): Next.js Frontend on Vercel]
• pages/: index, campaign/[id], campaign/new, requests
• components/: Navbar, Footer, DarkModeSwitch
• Chakra UI styling
| (2) read/write calls via Web3.js
V
[Rectangle (green): Web3.js + lib/getETHPrice]
• web3.js → Infura provider (Rinkeby)
• getETHPrice.js → external price API
| (3) JSON-RPC over HTTPS/WebSocket
V
[Rectangle (orange): Ethereum Node (Infura)]
| (4) broadcast tx / query state
V
• Smart Contracts:
– CampaignFactory (creates Campaigns)
– Campaign (manages contributions & requests)
[compile.js] → build/*.json (ABI)
|
[deploy.js] → writes deployed address → factory.js config
Relationships & Interactions
a. Browser ↔ Frontend: UI events trigger React components → Web3 calls.
b. Frontend → Ethereum Node: via web3.js & Infura (read/write).
c. Ethereum Node → Blockchain: transaction propagation & state queries.
d. Dev scripts: compile.js & deploy.js run off-chain to prepare and deploy contracts.
Architectural Patterns & Principles
• Separation of concerns:
• UI layer (Next.js)
• Blockchain logic (Solidity contracts)
• Integration layer (Web3.js)
• Serverless + CDN hosting (Vercel) for frontend.
• Immutable, transparent on-chain storage for campaign data.