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.
- 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
/
├── 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
-
Network Analytics Dashboard
- Recent blocks and transactions
- Network statistics
- Top wallets and smart contracts
- Transaction growth visualization
-
Address-specific Analytics
- ERC20 token balances with pricing
- NFT collection display
- Transaction history
The project uses Jest and React Testing Library for unit testing components and functionality.
pnpm testTo run a specific test file:
pnpm test -- __tests__/components/AddressSearch.test.tsxTests 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
The AddressSearch component test verifies:
- The component renders correctly with input field and search button
- Error handling for empty or invalid Ethereum addresses
- Navigation to the correct address page when a valid address is submitted
- Error message clearing when the user starts typing after an error
- Address overview with balance and transaction count
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 }
}
})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),
})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
}The application integrates with several Alchemy API endpoints:
- Token Data: Fetches ERC20 token balances for addresses
- NFT Data: Retrieves NFT collections owned by addresses
- Transaction Data: Gets transaction history for addresses
- Network Data: Fetches network statistics and block information
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
- Server-side Rendering: Critical data is fetched on the server using React Server Components and Server Actions
- Caching: Data fetching functions use React's cache function to prevent redundant API calls
- Image Optimization: Next.js Image component is used for optimized image loading
- Pagination: Large datasets are paginated to improve loading times
The project includes:
- Unit tests with Jest
- End-to-end tests with Playwright
- Local Development:
npm run dev(uses Next.js with Turbopack) - Building:
npm run build - Production Start:
npm run start - Linting:
npm run lint - Formatting:
npm run format - Testing:
npm run test(unit tests) ornpm run test:e2e(end-to-end tests)
Required environment variables:
ALCHEMY_API_KEY: API key for Alchemy servicesETHERSCAN_API_KEY: API key for Etherscan (optional)
- Enhanced Caching: Implement more sophisticated caching strategies
- Real-time Updates: Add WebSocket connections for real-time blockchain data
- More Visualizations: Expand the data visualization capabilities
- Token Price History: Add historical price data for tokens
- Gas Fee Estimator: Add gas fee estimation tools
- Multi-chain Support: Extend support to other EVM-compatible blockchains