This guide documents the automatic real-time flood level data integration from the USGS (United States Geological Survey) water monitoring system into the Paramify flood insurance application.
-
Backend Service (
backend/server.js)- Node.js/Express server running on port 3001
- Fetches USGS data every 5 minutes
- Updates the smart contract oracle automatically
- Provides REST API for frontend
-
Frontend Integration
- Admin Dashboard shows real-time USGS data status
- Customer Dashboard displays live flood levels
- Auto-refreshes every 10 seconds
-
Smart Contract Integration
- Mock Oracle contract receives automatic updates
- Flood levels converted from feet to units (1 ft = 1000 units)
- Monitoring Location: 01646500 (POTOMAC RIVER NEAR WASH, DC LITTLE FALLS PUMP STA)
- Parameter: Gage height (water level in feet)
- API Endpoint: USGS Instantaneous Values REST Web Service
- Update Frequency: Every 5 minutes
# Install frontend dependencies
cd frontend
npm install
# Install backend dependencies
cd ../backend
npm installThe backend uses environment variables configured in backend/.env:
# Backend Server Configuration
PORT=3001
# Ethereum Configuration
RPC_URL=http://localhost:8545
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
PARAMIFY_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3
MOCK_ORACLE_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
# USGS Configuration
USGS_SITE_ID=01646500
USGS_PARAMETER_CODE=00065
# Update Interval (in minutes)
UPDATE_INTERVAL=5-
Start Hardhat Node (if not already running):
npx hardhat node
-
Deploy Contracts (if not already deployed):
npx hardhat run scripts/deployMock.js --network localhost
-
Start Backend Service:
cd backend npm start -
Start Frontend:
cd frontend npm run dev
- Backend fetches USGS data every 5 minutes
- Automatically updates the oracle contract
- No manual intervention required
- Live connection status indicator
- Current water level in feet and units
- Next update countdown timer
- Data source information
- Last update timestamp
- Admin dashboard includes "Manual Update" button
- Triggers immediate USGS data fetch
- Useful for testing or urgent updates
- Graceful handling of USGS API downtime
- Fallback to last known values
- Clear error messages in UI
- Automatic retry mechanism
-
GET /api/flood-data
- Returns current USGS flood data
- Response format:
{ "value": 3.45, "timestamp": "2024-06-25T10:30:00.000Z", "status": "success", "source": "USGS API", "siteInfo": { "name": "POTOMAC RIVER NEAR WASH, DC", "siteId": "01646500" } } -
GET /api/status
- Returns service status and oracle information
- Response format:
{ "service": "USGS Flood Data Service", "lastUpdate": "2024-06-25T10:30:00.000Z", "currentFloodLevel": 3.45, "oracleValue": 3.45, "dataSource": "USGS Water Services", "updateInterval": "5 minutes", "nextUpdate": "2024-06-25T10:35:00.000Z" } -
POST /api/manual-update
- Triggers immediate USGS data fetch
- Admin-only endpoint
-
GET /api/health
- Health check endpoint
- Returns service status
-
USGS API → Backend Service
- Fetch current water level data
- Parse XML response
- Extract gage height value
-
Backend Service → Oracle Contract
- Convert feet to contract units (×1000)
- Convert to 8 decimal format
- Update oracle answer
-
Oracle Contract → Paramify Contract
- Paramify reads latest price from oracle
- Uses for insurance calculations
-
Backend Service → Frontend
- REST API provides current data
- WebSocket updates (future enhancement)
# Check backend logs
# Should see: "Fetching USGS data..."
# And: "USGS data fetched successfully"- Open Admin Dashboard
- Observe "USGS Real-Time Data" section
- Verify water level matches USGS website
- Click "Manual Update" button
- Check console for update confirmation
- Verify new data appears
- Watch "Next Update In" countdown
- Verify updates occur every 5 minutes
- Check oracle value changes
- Ensure Hardhat node is running
- Check contract addresses in .env
- Verify private key is correct
- Check internet connection
- Verify USGS API is accessible
- Check backend console for errors
- Try manual update button
- Ensure backend is running on port 3001
- Check browser console for errors
- Verify CORS is enabled
- Use environment variables for sensitive data
- Implement rate limiting for API endpoints
- Add authentication for admin endpoints
- Use HTTPS in production
- Implement database for data persistence
- Add backup data sources
- Use process manager (PM2) for backend
- Set up monitoring and alerts
- Consider caching USGS responses
- Implement WebSocket for real-time updates
- Use message queue for oracle updates
- Add load balancing for multiple instances
-
Multiple Data Sources
- Add NOAA data integration
- Support multiple monitoring stations
- Aggregate data from multiple sources
-
Advanced Features
- Historical data tracking
- Flood prediction algorithms
- Alert system for threshold breaches
- Mobile app notifications
-
Blockchain Improvements
- Decentralized oracle network
- Multiple oracle providers
- On-chain data validation
- Chainlink integration
For issues or questions:
- Check backend logs for errors
- Verify all services are running
- Ensure correct network configuration
- Review this documentation
This integration is part of the Paramify project and follows the same license terms.