Skip to content
SmarttDevPublic

About

Ethereum Analytics Dashboard

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Ethereum Analytics Dashboard - Technical Documentation

Project Overview

This project is a web application that provides analytics for Ethereum blockchain data, including network statistics and wallet-specific information. It's built with modern web technologies and follows best practices for React, Next.js, and TypeScript development.

Tech Stack

  • Frontend Framework: Next.js 15.3.3 (React 19)
  • Language: TypeScript
  • Styling: TailwindCSS 4
  • UI Components: Custom components with Radix UI primitives
  • Data Fetching: React Server Actions
  • Blockchain Interaction: Viem, Ethers.js
  • API Integration: Alchemy API for blockchain data
  • Visualization: Recharts, D3.js
  • State Management: React Hooks
  • Testing: Jest for unit testing, Playwright for E2E testing

Project Structure

/
├── public/             # Static assets and compiled version
├── src/
│   ├── app/            # Next.js app router pages
│   ├── components/     # React components
│   ├── hooks/          # Custom React hooks
│   ├── lib/            # Utility functions and server actions
│   │   ├── actions/    # React Server Actions
│   │   └── data.ts     # Blockchain client setup
│   ├── styles/         # Global styles
│   └── types/          # TypeScript type definitions
├── package.json        # Dependencies and scripts
├── next.config.ts      # Next.js configuration
└── tsconfig.json       # TypeScript configuration

Key Features

  1. Network Analytics Dashboard

    • Recent blocks and transactions
    • Network statistics
    • Top wallets and smart contracts
    • Transaction growth visualization
  2. Address-specific Analytics

    • ERC20 token balances with pricing
    • NFT collection display
    • Transaction history

Testing

Unit Tests

The project uses Jest and React Testing Library for unit testing components and functionality.

Running Tests

pnpm test

To run a specific test file:

pnpm test -- __tests__/components/AddressSearch.test.tsx

Test Structure

Tests are organized in the __tests__ directory, mirroring the structure of the src directory:

__tests__/
├── components/        # Tests for React components
│   └── AddressSearch.test.tsx
└── hooks/            # Tests for custom hooks

Example Test: AddressSearch Component

The AddressSearch component test verifies:

  1. The component renders correctly with input field and search button
  2. Error handling for empty or invalid Ethereum addresses
  3. Navigation to the correct address page when a valid address is submitted
  4. Error message clearing when the user starts typing after an error
    • Address overview with balance and transaction count

Core Components

Data Fetching

The application uses React Server Actions for data fetching, which provides several benefits:

  • Server-side execution for better performance
  • Built-in caching with the React cache function
  • Type safety with TypeScript

Example server action:

// src/lib/actions/getAddressInfos.ts
export const getAddressInfos = cache(async (address: `0x${string}`): Promise<AddressInfos> => {
  try {
    const [balance, txCount] = await Promise.all([
      client.getBalance({ address }),
      client.getTransactionCount({ address }),
    ])
    return { balance, txCount }
  } catch (error) {
    console.warn(error)
    return { balance: 0n, txCount: 0 }
  }
})

Blockchain Client

The application uses Viem as the primary Ethereum client library:

// src/lib/data.ts
export const client = createPublicClient({
  chain: mainnet,
  transport: http(ALCHEMY_ETH_NODE_URL + alchemyApiKey),
})

Data Hooks

Custom hooks manage data fetching and state for components:

// src/hooks/useAddressData.ts
export function useAddressData(address: `0x${string}`): AddressData {
  // Implementation that fetches and manages address data
}

API Integration

The application integrates with several Alchemy API endpoints:

  1. Token Data: Fetches ERC20 token balances for addresses
  2. NFT Data: Retrieves NFT collections owned by addresses
  3. Transaction Data: Gets transaction history for addresses
  4. Network Data: Fetches network statistics and block information

Type Safety

TypeScript is used throughout the application to ensure type safety. Key types include:

  • Blockchain data types (transactions, blocks, addresses)
  • API response types for external services
  • Component prop types
  • State management types

Performance Considerations

  1. Server-side Rendering: Critical data is fetched on the server using React Server Components and Server Actions
  2. Caching: Data fetching functions use React's cache function to prevent redundant API calls
  3. Image Optimization: Next.js Image component is used for optimized image loading
  4. Pagination: Large datasets are paginated to improve loading times

Testing

The project includes:

  • Unit tests with Jest
  • End-to-end tests with Playwright

Development Workflow

  1. Local Development: npm run dev (uses Next.js with Turbopack)
  2. Building: npm run build
  3. Production Start: npm run start
  4. Linting: npm run lint
  5. Formatting: npm run format
  6. Testing: npm run test (unit tests) or npm run test:e2e (end-to-end tests)

Environment Variables

Required environment variables:

  • ALCHEMY_API_KEY: API key for Alchemy services
  • ETHERSCAN_API_KEY: API key for Etherscan (optional)

Future Improvements

  1. Enhanced Caching: Implement more sophisticated caching strategies
  2. Real-time Updates: Add WebSocket connections for real-time blockchain data
  3. More Visualizations: Expand the data visualization capabilities
  4. Token Price History: Add historical price data for tokens
  5. Gas Fee Estimator: Add gas fee estimation tools
  6. Multi-chain Support: Extend support to other EVM-compatible blockchains

About

Ethereum Analytics Dashboard

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages