Real-time dApp analytics with sub-second latency powered by Somnia Data Streams SDK
A production-ready analytics platform that enables dApp developers to track user behavior, monitor performance, and gain instant insights with <1 second latency - impossible to achieve without Somnia's Data Streams technology.
Traditional blockchain analytics suffer from significant delays:
- Block confirmations take 12+ seconds
- Indexing services lag by minutes or hours
- No real-time user behavior tracking
- Delayed insights impact decision-making
- Poor user experience due to data staleness
Our platform leverages Somnia Data Streams SDK to deliver:
- <1 second latency - See events as they happen
- Real-time metrics - Active users, success rates, gas usage
- User journey tracking - Understand user flows instantly
- Live alerts - Get notified of critical events immediately
- Interactive dashboards - Monitor your dApp in real-time
This is impossible without Data Streams. Traditional approaches would require polling, manual indexing, or waiting for block confirmations - all adding seconds or minutes of delay.
- Live Metrics: Active users, transactions, success rates, gas usage
- Transaction Charts: Visualize successful vs failed transactions
- Active Sessions: Monitor user engagement in real-time
- Event Feed: Stream of all dApp interactions with <1s latency
- Timeline View: See user actions chronologically with time gaps
- Flow Diagram: Visualize user paths through your dApp
- Funnel Analysis: Track conversion rates across stages (Connect β Approve β Execute β Confirm β Results)
- High gas usage spikes (>50% above average)
- Transaction failure rates (>10% in 5 min)
- Unusual user activity (>10x normal)
- High-value transactions
- Error pattern detection
- Desktop notifications and sound alerts
- Full DEX functionality with constant product AMM
- Automatic analytics logging
- Transaction history
- Slippage protection
- Price impact calculation
- Multiple formats: CSV, JSON, Excel
- Configurable date ranges
- Selective data export (transactions, users, events, metrics)
- Export history with 7-day retention
- Easy onboarding for new dApps
- Support for multiple contract addresses
- Category tagging (DeFi, NFT, Gaming, Social, DAO)
- Logo upload
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (React) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Dashboard β β Journey β β Alerts β β
β β Components β β Visualizer β β System β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Real-Time Hooks (Custom React Hooks) β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Data Streams Service (SDK Integration) β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β WebSocket (<1s latency)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Somnia Data Streams SDK β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Somnia Testnet (Chain 50311) β
β ββββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββ β
β β Analytics β β Event β β Session β β Metrics β β
β β Registry β β Logger β β Manager β βAggregatorβ β
β ββββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββ β
β β β β β β
β ββββββββββββββββββ΄ββββββββββββββββ΄βββββββββββββββ β
β β β
β ββββββββββββββββ β
β β SimpleSwap β (Demo DEX) β
β β (DEX AMM) β β
β ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Solidity 0.8.20 - Smart contract language
- Hardhat 2.27.0 - Development environment
- OpenZeppelin 5.4.0 - Secure contract library
- ethers.js 6.15.0 - Blockchain interaction
- TypeChain 8.3.2 - TypeScript bindings
- React 19.2.0 - UI framework
- TypeScript 5.9.3 - Type safety
- Vite 7.2.2 - Build tool and dev server
- Tailwind CSS 4.1.17 - Styling
- Recharts 3.4.1 - Data visualization
- React Query 5.90.8 - Data fetching
- Somnia Testnet - Chain ID: 50311
- Data Streams SDK 0.9.5 - Real-time event streaming
- RPC: https://dream-rpc.somnia.network
- Explorer: https://explorer-test.somnia.network
User Action β Block Mined (12s) β Indexer Processes (60s+) β API Updates (10s)
Total Latency: 82+ seconds
User Action β Event Emitted β Data Streams β React Hook Update
Total Latency: <1 second
1. Service Layer (services/dataStreamsService.ts)
// Initialize connection
await dataStreamsService.initialize();
// Subscribe to events
const subscription = await dataStreamsService.subscribe(
'EventLogger',
'EventLogged',
(event) => {
// Handle event in <1 second
updateUI(event);
}
);2. React Hooks (hooks/useRealTimeEvents.ts)
const { events, isConnected } = useRealTimeEvents({
dAppId: 1,
limit: 50
});
// Events update automatically with <1s latency3. Auto-Reconnection
// Handles network failures with exponential backoff
// Maintains subscription registry
// Zero configuration required| Feature | Traditional | Data Streams |
|---|---|---|
| Latency | 60-300s | <1s |
| Polling Required | Yes (expensive) | No |
| Real-time Updates | No | Yes |
| Server Infrastructure | Complex indexers | SDK handles it |
| User Experience | Stale data | Live updates |
| Contract | Address | Explorer |
|---|---|---|
| AnalyticsRegistry | 0x5FbDB2315678afecb367f032d93F642f64180aa3 |
View |
| EventLogger | 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 |
View |
| SessionManager | 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 |
View |
| MetricsAggregator | 0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 |
View |
| SimpleSwap | 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9 |
View |
cd contracts
npm testCoverage:
- β 72 tests passing
- β >80% code coverage
- β All critical paths tested
Test Suites:
- AnalyticsRegistry (23 tests)
- EventLogger (20 tests)
- SessionManager (15 tests)
- MetricsAggregator (14 tests)
- SimpleSwap (29 tests)
somnia-analytics-platform/
βββ contracts/ # Smart contracts
β βββ src/ # Solidity source files
β β βββ AnalyticsRegistry.sol # dApp registry (225 lines)
β β βββ EventLogger.sol # Event logging (336 lines)
β β βββ SessionManager.sol # Session tracking (324 lines)
β β βββ MetricsAggregator.sol # Metrics (371 lines)
β β βββ SimpleSwap.sol # Demo DEX (359 lines)
β βββ test/ # 72 comprehensive tests
β βββ scripts/deploy.ts # Deployment script
β βββ deployments/ # Deployment records
β
βββ frontend/ # React frontend
β βββ src/
β β βββ components/ # 9 major components
β β β βββ MetricsOverview.tsx
β β β βββ LiveActivityFeed.tsx
β β β βββ TransactionChart.tsx
β β β βββ ActiveSessionsPanel.tsx
β β β βββ UserJourneyMap.tsx
β β β βββ RegisterDApp.tsx
β β β βββ SwapInterface.tsx
β β β βββ AlertsPanel.tsx
β β β βββ DataExporter.tsx
β β βββ hooks/ # Custom React hooks
β β β βββ useRealTimeEvents.ts
β β β βββ useRealTimeMetrics.ts
β β β βββ useActiveSessions.ts
β β β βββ useUserJourney.ts
β β βββ services/
β β β βββ dataStreamsService.ts # Data Streams SDK wrapper
β β β βββ contractService.ts # Smart contract interface
β β βββ config/ # Network & contract config
β βββ package.json
β
βββ docs/ # Documentation
- Monitor swap volumes in real-time
- Track liquidity provider activity
- Detect unusual trading patterns
- Optimize gas usage
- Track minting activity live
- Monitor marketplace transactions
- Analyze user behavior patterns
- Detect bot activity
- Real-time player tracking
- Session duration analysis
- In-game transaction monitoring
- Retention metrics
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Somnia Network - For the incredible Data Streams SDK that makes real-time analytics possible
- OpenZeppelin - For battle-tested smart contract libraries
- Recharts - For beautiful data visualization components
- The Ethereum Community - For continuous innovation
Built with β€οΈ for the Somnia Hackathon