Skip to content

Repository files navigation

🌟 OpenCause

Transparent Crowdfunding Platform with Blockchain Escrow

Every rupee tracked. Every milestone proven. Every cause transparent.

TypeScript Next.js NestJS Node.js pnpm

Features β€’ Tech Stack β€’ Getting Started β€’ Architecture β€’ API Documentation β€’ Contributing


πŸ“– About

OpenCause is a revolutionary crowdfunding platform that brings transparency and trust to charitable giving through blockchain technology. Unlike traditional crowdfunding platforms, OpenCause escrows all donations in smart contracts, ensuring funds are only released when organizers provide verifiable proof of milestone completion.

Key Differentiators

  • πŸ”’ Smart Contract Escrow - All funds held securely in on-chain vaults until milestones are proven
  • πŸ“„ Evidence-Based Releases - Every withdrawal requires verifiable proof bundles anchored on-chain
  • πŸ’Ž Dual Payment Rails - Accept donations in INR (UPI/cards) or 100+ cryptocurrencies
  • πŸ†” Web3 Identity - DID/VC-based KYC without storing PII on-chain for privacy
  • πŸ‘οΈ Public Transparency - Complete ledger of all transactions, proofs, and releases publicly verifiable
  • πŸ›‘οΈ Anti-Fraud Protection - Duplicate detection, anomaly scoring, and automated safeguards

✨ Features

For Donors

  • 🎯 Browse Campaigns - Discover verified campaigns with transparent milestones
  • πŸ’° Multiple Payment Options - Donate via UPI, cards, or 100+ cryptocurrencies
  • πŸ“Š Real-time Tracking - See exactly how your donations are being used
  • πŸ” Proof Verification - Verify evidence and milestone completion on-chain
  • πŸ“± Mobile-Friendly - Responsive design for seamless mobile experience

For Organizers

  • πŸš€ Easy Campaign Creation - Set up campaigns with clear milestones and funding goals
  • πŸ’Ό Smart Contract Vaults - Each campaign gets its own secure on-chain vault
  • πŸ“Έ Evidence Submission - Upload proof bundles (images, documents) anchored to IPFS
  • πŸ’Έ Flexible Withdrawals - Request withdrawals with evidence-backed milestones
  • πŸ“ˆ Analytics Dashboard - Track donations, milestones, and campaign performance

For Reviewers

  • βœ… Evidence Review - Verify proof bundles before fund release
  • πŸ” Role-Based Access - Secure reviewer authentication and permissions
  • πŸ“‹ Review Dashboard - Streamlined interface for reviewing withdrawal requests
  • ⚑ Quick Approval - Efficient workflow for evidence verification

Platform Features

  • 🌐 Multi-Chain Support - Ethereum, Polygon, BSC, Arbitrum, Optimism, Avalanche, Base, Fantom, Bitcoin, Litecoin, Solana
  • πŸͺ™ 100+ Cryptocurrencies - Support for major tokens across all chains
  • πŸ”„ Real-time Indexing - Automated blockchain transaction monitoring
  • πŸ“¦ IPFS Integration - Decentralized storage for evidence and proofs
  • πŸ”” Notifications - Real-time updates on campaign activities
  • πŸ“Š The Graph Subgraph - Indexed blockchain data for fast queries

πŸ› οΈ Tech Stack

Frontend

Backend

  • Framework: NestJS with Fastify
  • Language: TypeScript
  • Authentication: JWT with Passport.js
  • Validation: class-validator, class-transformer
  • Rate Limiting: @nestjs/throttler
  • Error Tracking: Sentry

Blockchain & Smart Contracts

  • Solidity: Smart contracts written in Solidity
  • Testing: Foundry
  • Networks:
    • EVM: Ethereum, Polygon, BSC, Arbitrum, Optimism, Avalanche, Base, Fantom
    • UTXO: Bitcoin, Litecoin
    • Solana: Mainnet
  • Indexing: The Graph Protocol (Subgraph)
  • HD Wallets: BIP32/BIP39 for deterministic address generation

Infrastructure

  • Database: Firebase Firestore
  • File Storage: Cloudflare R2, IPFS
  • Payments: Razorpay, Cashfree
  • Worker: Background job processing for blockchain indexing
  • Deployment: Vercel (API), Railway, Docker

Development Tools

  • Package Manager: pnpm with workspaces
  • Build System: Turbo (monorepo)
  • Linting: ESLint
  • Testing: Jest
  • Type Checking: TypeScript

πŸš€ Getting Started

Prerequisites

  • Node.js >= 20.0.0
  • pnpm >= 8.0.0
  • Git
  • Firebase Account (for Firestore)
  • Blockchain RPC URLs (Alchemy, Infura, or public RPCs)
  • Payment Gateway Keys (Razorpay/Cashfree - optional for development)

Installation

  1. Clone the repository

    git clone https://github.com/devanshranjan10/opencausepublic.git
    cd opencausepublic
  2. Install dependencies

    pnpm install
  3. Set up environment variables

    Create .env files in the respective app directories:

    apps/api/.env

    # Server
    PORT=4000
    NODE_ENV=development
    
    # Firebase
    FIREBASE_PROJECT_ID=your-project-id
    FIREBASE_CLIENT_EMAIL=your-service-account-email
    FIREBASE_PRIVATE_KEY=your-private-key
    
    # JWT
    JWT_SECRET=your-jwt-secret
    JWT_EXPIRES_IN=7d
    
    # Blockchain RPC URLs
    ETHEREUM_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
    POLYGON_RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/YOUR_KEY
    BSC_RPC_URL=https://bsc-dataseed.binance.org
    ARBITRUM_RPC_URL=https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY
    OPTIMISM_RPC_URL=https://opt-mainnet.g.alchemy.com/v2/YOUR_KEY
    AVALANCHE_RPC_URL=https://api.avax.network/ext/bc/C/rpc
    BASE_RPC_URL=https://mainnet.base.org
    FANTOM_RPC_URL=https://rpc.ftm.tools
    SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
    
    # Payment Gateways (Optional)
    RAZORPAY_KEY_ID=your-razorpay-key
    RAZORPAY_KEY_SECRET=your-razorpay-secret
    CASHFREE_APP_ID=your-cashfree-app-id
    CASHFREE_SECRET_KEY=your-cashfree-secret
    
    # IPFS
    IPFS_API_URL=https://ipfs.infura.io:5001/api/v0
    IPFS_PROJECT_ID=your-infura-project-id
    IPFS_PROJECT_SECRET=your-infura-secret
    
    # Cloudflare R2 (Optional)
    R2_ACCOUNT_ID=your-r2-account-id
    R2_ACCESS_KEY_ID=your-access-key
    R2_SECRET_ACCESS_KEY=your-secret-key
    R2_BUCKET_NAME=your-bucket-name
    
    # Sentry (Optional)
    SENTRY_DSN=your-sentry-dsn
    
    # Frontend URL
    FRONTEND_URL=http://localhost:3000

    apps/web/.env.local

    # Next.js
    NEXT_PUBLIC_API_URL=http://localhost:4000
    
    # Firebase
    NEXT_PUBLIC_FIREBASE_API_KEY=your-firebase-api-key
    NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
    NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
    NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
    NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your-sender-id
    NEXT_PUBLIC_FIREBASE_APP_ID=your-app-id
    NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=your-measurement-id
    
    # NextAuth
    NEXTAUTH_URL=http://localhost:3000
    NEXTAUTH_SECRET=your-nextauth-secret
    
    # Sentry (Optional)
    NEXT_PUBLIC_SENTRY_DSN=your-sentry-dsn
  4. Build shared packages

    pnpm --filter @opencause/types build
    pnpm --filter @opencause/crypto-core build
    pnpm --filter @opencause/firebase build
    pnpm --filter @opencause/policy build
    pnpm --filter @opencause/r2 build
  5. Run development servers

    Option 1: Run both apps together (recommended)

    pnpm dev

    Option 2: Run apps separately

    # Terminal 1 - API
    cd apps/api
    pnpm dev
    
    # Terminal 2 - Web
    cd apps/web
    pnpm dev
  6. Access the applications

Running the Worker

The worker processes blockchain transactions and indexes events:

cd apps/worker
pnpm dev

Building for Production

# Build all packages and apps
pnpm build

# Or use the production build script
./build-production.sh

πŸ—οΈ Architecture

Monorepo Structure

opencausepublic/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ api/              # NestJS backend API
β”‚   β”œβ”€β”€ web/              # Next.js frontend
β”‚   β”œβ”€β”€ worker/           # Background job processor
β”‚   β”œβ”€β”€ contracts/        # Solidity smart contracts
β”‚   └── subgraph/         # The Graph subgraph
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ crypto-core/      # Cryptocurrency utilities
β”‚   β”œβ”€β”€ firebase/         # Firebase/Firestore utilities
β”‚   β”œβ”€β”€ policy/           # Business logic & policies
β”‚   β”œβ”€β”€ r2/               # Cloudflare R2 storage
β”‚   β”œβ”€β”€ types/            # Shared TypeScript types
β”‚   └── testkit/          # Testing utilities
└── ...

System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Next.js Web   β”‚
β”‚   (Frontend)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚ HTTP/REST
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   NestJS API    β”‚
β”‚   (Backend)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚         β”‚              β”‚             β”‚
β”Œβ”€β”€β”€β–Όβ”€β”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”
β”‚ Fire- β”‚ β”‚ IPFS β”‚    β”‚  Blockchain β”‚ β”‚Paymentβ”‚
β”‚ base  β”‚ β”‚      β”‚    β”‚   Networks  β”‚ β”‚Gatewayβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                         β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
                         β”‚  Worker β”‚
                         β”‚(Indexer)β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Smart Contract Architecture

  • CampaignFactory: Deploys new campaign vaults
  • CampaignVault: Holds funds in escrow for each campaign
  • CampaignNativeVault: For native tokens (ETH, MATIC, etc.)
  • CampaignTokenVault: For ERC20 tokens (USDC, USDT, etc.)
  • EvidenceRegistry: Stores evidence hashes on-chain
  • RoleRegistry: Manages user roles and permissions

Data Flow

  1. Campaign Creation: Organizer creates campaign β†’ Smart contract vault deployed
  2. Donation: Donor contributes β†’ Funds escrowed in smart contract
  3. Milestone Completion: Organizer submits evidence β†’ Evidence pinned to IPFS β†’ Hash stored on-chain
  4. Withdrawal Request: Organizer requests withdrawal β†’ Evidence reviewed
  5. Fund Release: Reviewer approves β†’ Funds released from smart contract to payee

πŸ“š API Documentation

Base URL

Development: http://localhost:4000
Production: https://api.opencause.world

Authentication

Most endpoints require JWT authentication. Include the token in the Authorization header:

Authorization: Bearer <your-jwt-token>

Key Endpoints

Campaigns

  • GET /campaigns - List all campaigns
  • GET /campaigns/:id - Get campaign details
  • POST /campaigns - Create new campaign (requires auth)
  • PUT /campaigns/:id - Update campaign (requires auth)

Donations

  • POST /donations - Create donation
  • GET /donations - List donations (with filters)
  • GET /donations/:id - Get donation details

Crypto Payments

  • POST /crypto/payment-intents - Create crypto payment intent
  • GET /crypto/payment-intents/:id - Get payment intent status
  • POST /crypto/verify - Verify crypto transaction
  • GET /crypto/prices - Get cryptocurrency prices

Withdrawals

  • POST /withdrawals - Request withdrawal (requires auth)
  • GET /withdrawals - List withdrawals
  • GET /withdrawals/:id - Get withdrawal details
  • PUT /withdrawals/:id/approve - Approve withdrawal (reviewer only)

Evidence

  • POST /evidence - Submit evidence bundle
  • GET /evidence/:id - Get evidence details
  • GET /evidence/campaign/:campaignId - Get all evidence for campaign

KYC

  • POST /kyc/submit - Submit KYC documents
  • GET /kyc/status - Get KYC status
  • POST /kyc/verify - Verify KYC (admin only)

Health & Stats

  • GET /health - Health check endpoint
  • GET /stats - Platform statistics

πŸ” Security

OpenCause implements multiple layers of security:

  • Smart Contract Escrow: Funds cannot be accessed without proper authorization
  • Evidence Verification: All evidence is hashed and stored on-chain
  • Rate Limiting: API endpoints are rate-limited to prevent abuse
  • JWT Authentication: Secure token-based authentication
  • Input Validation: All inputs validated using class-validator
  • CORS Protection: Configured CORS for allowed origins
  • Security Headers: XSS, CSRF, and other security headers
  • Private Key Management: HD wallets with secure key derivation
  • PII Protection: KYC data encrypted, not stored on-chain

πŸ§ͺ Testing

# Run all tests
pnpm test

# Run API tests
pnpm --filter api test

# Run tests in watch mode
pnpm test:watch

# Run tests with coverage
pnpm test:cov

# Test smart contracts
cd apps/contracts
forge test

πŸ“¦ Deployment

Vercel (Recommended for API)

The API is configured for Vercel serverless deployment:

cd apps/api
vercel deploy

Manual Deployment

  1. Build the project:

    pnpm build
  2. Set production environment variables

  3. Start the API:

    cd apps/api
    pnpm start:prod
  4. Start the web app:

    cd apps/web
    pnpm start

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

Development Guidelines

  • Follow TypeScript best practices
  • Write tests for new features
  • Update documentation as needed
  • Follow the existing code style
  • Ensure all tests pass before submitting PR

πŸ™ Acknowledgments

  • NestJS - Progressive Node.js framework
  • Next.js - React framework for production
  • Ethers.js - Ethereum library
  • The Graph - Decentralized indexing protocol
  • IPFS - Distributed file system
  • Firebase - Backend infrastructure

πŸ“ž Support

For support, email admin@opencause.world or open an issue in this repository.


🌟 Star History

Star History Chart


Made with ❀️ by the Team ZenTechs

About

OpenCause is a revolutionary crowdfunding platform that brings transparency and trust to charitable giving through blockchain technology. Unlike traditional crowdfunding platforms, OpenCause escrows all donations in smart contracts, ensuring funds are only released when organizers provide verifiable proof of milestone completion.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages