Skip to content

cavemansatyn-design/Disaster-Insurance-Smart-Contract-System-Solidity-Hardhat-React

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Disaster Insurance — Parametric Insurance dApp

System flow (screenshots)

The screenshots below are in order of use: from opening the app through connecting the wallet, entering details, confirming the transaction, and seeing the result. Recruiters can follow the full flow without running the app.

Step Description Screenshot
1 App loads / landing Step 1
2 Connect wallet prompt Step 2
3 Wallet connected / form Step 3
4 Enter risk score & premium Step 4
5 Buy insurance action Step 5
6 MetaMask confirmation Step 6
7 Transaction submitted Step 7
8 Transaction confirmed Step 8
9 Success / policy feedback Step 9
10 Final state / overview Step 10

A blockchain-based parametric disaster insurance application. Users purchase policies by paying a premium and providing a risk score; an admin can trigger payouts (5× premium) for valid policies within the policy window.


Project Overview

This repository contains a full-stack dApp for parametric disaster insurance:

  • Smart contract — On-chain policy creation and payout logic (Solidity).
  • Blockchain tooling — Hardhat for local development, testing, and deployment.
  • Frontend — React (Vite) app for wallet connection and policy purchase.
  • Backend — Placeholder for a future risk-score API.

The system is intended for development and demonstration on a local Hardhat network. No real funds are used.


Problem Statement

Traditional disaster insurance often involves slow, opaque claims and centralized underwriting. This project explores a parametric model:

  • Parametric — Payout conditions are predefined (e.g. admin-attested qualifying event).
  • On-chain — Policies and payouts are recorded on a blockchain for transparency and auditability.
  • Transparent rules — Minimum risk score, policy duration (30 days), and payout multiplier (5×) are enforced in the contract.

Features

  • Purchase insurance — Connect MetaMask, enter risk score (60–100) and premium (ETH), and buy a policy in one transaction.
  • On-chain policies — Each policy is stored on the contract with a unique ID, premium, risk score, and expiry.
  • Admin payouts — Designated admin can trigger one payout per policy (5× premium) before the 30-day window expires.
  • Service-layer frontend — Clear separation between UI, risk logic, and contract interaction; ready for a future risk-score API.
  • Test suite — Hardhat tests for deployment, purchase, payout, admin, and view functions.

Architecture

  • contracts/ — Solidity source (DisasterInsurance.sol).
  • blockchain/ — Hardhat config, deploy/utility scripts, and tests (contracts compiled from ../contracts).
  • frontend/ — React app and services (wallet, risk, insurance); reads contract address and ABI from config.
  • backend/ — Future API for risk score calculation.
  • docs/ — Architecture, deployment, smart contract design, and walkthrough.

High-level flow: User → Frontend (MetaMask) → Local chain → Contract. Admin actions (payouts) are performed via scripts or a future admin UI.

See docs/architecture.md and docs/system-design.md for details.


Tech Stack

Layer Technology
Smart contract Solidity ^0.8.24
Blockchain Hardhat (local node, compile, test)
Frontend React, Vite, ethers.js v5
Wallet MetaMask (or compatible)
Backend Planned (e.g. Node/Express)

Smart Contract Design

  • Constants: Policy duration 30 days, payout 5× premium, minimum risk score 60 (max 100).
  • Roles: Single admin (deployer by default); only admin can call triggerPayout and changeAdmin.
  • State: Policies stored by ID; each policy has policyholder, premium, purchase time, risk score, and payoutClaimed flag.
  • Events: PolicyPurchased, PayoutTriggered.

See docs/smart-contract-design.md for full design and security notes.


Setup Instructions

Prerequisites

  • Node.js v16+
  • npm
  • MetaMask (for the frontend)

Install and compile

# From project root
cd blockchain && npm install --legacy-peer-deps
cd ../frontend && npm install
cd ..
npm run compile

Run local node and deploy

  1. Terminal 1 — start node:
    npm run node
    Leave it running.

  2. Terminal 2 — deploy:
    npm run deploy
    Copy the printed contract address.

  3. Configure frontend:
    Open frontend/src/config/contract.js and set CONTRACT_ADDRESS to the address from step 2.

  4. Optional — fund MetaMask:
    Set RECIPIENT to your MetaMask address and run npm run fund (with the node running).

  5. Start frontend:
    cd frontend && npm run dev
    Open http://localhost:5173 and add the Hardhat Local network in MetaMask (RPC http://127.0.0.1:8545, Chain ID 31337).

Detailed steps and troubleshooting: docs/RUN_PROJECT.md and docs/deployment-guide.md.


Demo Instructions

  1. Follow the setup above (node running, contract deployed, frontend configured and running).
  2. In the app: click Connect MetaMask, then enter Risk Score (e.g. 75) and Premium (ETH) (e.g. 0.1).
  3. Click Buy Insurance and confirm the transaction in MetaMask.
  4. To trigger a payout as admin: update CONTRACT_ADDRESS and POLICY_ID in blockchain/scripts/triggerPayout.js, then run:
    cd blockchain && npx hardhat run scripts/triggerPayout.js --network localhost
    See docs/ADMIN_PAYOUT_GUIDE.md for full admin flow.

Documentation

Document Description
docs/architecture.md High-level architecture and components
docs/system-design.md Problem, goals, and subsystems
docs/deployment-guide.md Build, run, and deploy steps
docs/smart-contract-design.md Contract design and security
docs/frontend-backend-flow.md Frontend–backend and future API
docs/walkthrough.md Step-by-step flow and design decisions
docs/RUN_PROJECT.md How to run the project
docs/ADMIN_PAYOUT_GUIDE.md Admin payout and verification

License

ISC

Disaster-Insurance-Smart-Contract-System-Solidity-Hardhat-React-

A blockchain-based insurance platform that calculates policy eligibility using location-based natural calamity risk scores. Developed Solidity smart contracts with Hardhat and Ethers.js, integrated MetaMask for transactions, and implemented premium-based payouts with an admin settlement process.

2a80615409b98c02fd541a3dc0ed018995c7c2de

About

A blockchain-based insurance platform that calculates policy eligibility using location-based natural calamity risk scores. Developed Solidity smart contracts with Hardhat and Ethers.js, integrated MetaMask for transactions, and implemented premium-based payouts with an admin settlement process.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors