This file provides guidance to WARP (warp.dev) when working with code in this repository.
This is a Decentralized KYC (Know Your Customer) system built on Ethereum using Hardhat for smart contract development, Express.js for the backend API, and React for the frontend. The system implements a blockchain-based identity verification platform with Decentralized Identifiers (DIDs) and Verifiable Credentials (VCs).
# Compile all Solidity contracts
npm run compile
# Run Hardhat tests
npm run test
# Start local Hardhat node for development
npm run node
# Deploy contracts to local network
npm run deploy:local
# Run specific test file
npx hardhat test tests/kyc.flow.test.js
# Clean Hardhat artifacts and cache
npx hardhat clean# Navigate to backend directory
cd backend
# Install dependencies
npm install
# Start backend server with nodemon (auto-reload)
npm start
# Backend runs on port specified in .env (copy from .env.example)# Navigate to React frontend
cd frontend-cra
# Install dependencies
npm install
# Start development server
npm start
# Runs on http://localhost:3000
# Build for production
npm run build
# Run React tests
npm testThe system consists of three main smart contracts working together:
-
IssuerRegistry.sol: OpenZeppelin AccessControl-based registry that manages approved issuers who can create/revoke credentials. Uses role-based permissions with DEFAULT_ADMIN_ROLE and ISSUER_ROLE.
-
DIDRegistry.sol: Manages Decentralized Identifiers (DIDs) for users. Supports user self-registration, issuer-based DID creation, self-revocation, and issuer-based revocation with reasons (Fraud, Expired, Regulatory).
-
CredentialRegistry.sol: Anchors credential hashes (bytes32) on-chain with issuance/revocation timestamps. Only approved issuers can anchor or revoke credentials. Stores credential metadata without exposing private data.
Located in backend/ with modular route structure:
src/routes/audit.routes.js- Audit trail endpointssrc/routes/user.routes.js- User managementsrc/routes/did.routes.js- DID operationssrc/routes/kyc.routes.js- KYC workflow endpointssrc/routes/vc.routes.js- Verifiable Credential operations
Key features:
- Webhook verification middleware with signature validation
- MongoDB integration for off-chain data storage
- IPFS integration via Pinata for document storage
- JWT authentication with access/refresh tokens
- Blockchain interaction via ethers.js
- Environment configuration via dotenv
- Located in
frontend-cra/ - Uses Tailwind CSS for styling with shadcn/ui components
- React Router for navigation
- Lucide React for icons
- Hardhat configuration supports local development and Polygon mainnet
- Contract addresses tracked in
migrationsDeployment/deployments.json - Environment variables defined in
backend/.env.example - Separate deployment scripts in
migrationsDeployment/directory
- Start local Hardhat node:
npm run node - Deploy contracts locally:
npm run deploy:local - Start backend API:
cd backend && npm start - Start React frontend:
cd frontend-cra && npm start - Update contract addresses in deployments.json after deployment
- Smart contract tests in
tests/directory using Hardhat/Waffle - End-to-end KYC flow testing in
tests/kyc.flow.test.js - React component tests using React Testing Library
- Backend API can be tested against the health endpoint:
/health
- Blockchain: Hardhat, ethers.js, OpenZeppelin contracts
- Backend: Express, MongoDB/Mongoose, Pinata SDK, JWT, bcrypt
- Frontend: React 19, React Router, Tailwind CSS, shadcn/ui
- Development: nodemon, dotenv, morgan logging
-
Copy
backend/.env.exampletobackend/.envand configure:- MongoDB connection
- Pinata IPFS credentials
- JWT secrets
- Blockchain RPC URL and private key
- CORS origins
-
Ensure you have a local Hardhat node running or access to Polygon network
-
Deploy contracts and update
migrationsDeployment/deployments.jsonwith deployed addresses
- If having issues with contract compilation, try clearing the cache with
npx hardhat clean - For contract verification issues, check that you're using the correct Solidity version (0.8.30)
- When testing with Hardhat, ensure you're using the correct network configuration in hardhat.config.cjs
- JWT token validation failures often relate to mismatched secrets in .env
- For IPFS storage issues, verify Pinata API keys and credentials
- MongoDB connection issues can be debugged by checking the connection string format
- MetaMask connectivity problems can be addressed by checking the network configuration
- If contract interactions fail, verify that the contract ABI and addresses match deployed contracts
- For styling issues, make sure Tailwind configuration is properly set up
- The codebase is set up to work with Polygon Mainnet (chainId 137) or Mumbai Testnet (chainId 80001)
- For local development, use Hardhat network (chainId 31337)
- Contract interactions use ethers.js wrapper functions found in
backend/src/config/blockchain.jsandfrontend-cra/src/lib/ethereum.js - When testing locally, the contracts expect a running Hardhat node on the default port (8545)
- Contract deployment addresses are tracked in
migrationsDeployment/contracts.json
For detailed analysis of common issues and their fixes, see FRONTEND_ISSUES_AND_FIXES.md which documents:
- JavaScript syntax errors and their corrections
- Missing configuration files and deployment setup
- Service management and port conflict resolution
- Complete before/after comparison with technical explanations