Data Module
Comprehensive blockchain data fetching and management for Solana assets, tokens, NFTs, and market information
The Data Module is your central hub for fetching, processing, and managing on-chain and off-chain data related to Solana assets. It provides seamless integration with multiple data sources including Helius, Birdeye, and CoinGecko.
Core Functionalities
Token Data
Fetch token metadata, balances, prices, and historical price data from multiple sources
NFT & Portfolio Assets
Retrieve user portfolio assets including NFTs and compressed NFTs (cNFTs)
Market Information
Access comprehensive market data from CoinGecko including OHLC and market details
Transaction History
Fetch and process user swap transaction history with enriched metadata
Installation & Setup
Environment Variables
Configure your API keys in .env.local
:
Import Module
Import the hooks and services you need:
Start Fetching
Use the hooks in your components to fetch data
Module Architecture
Core Services
tokenService.ts
- Core token data operations
tokenService.ts
- Core token data operations
coingeckoService.ts
- Market data from CoinGecko
tokenDetailsService.ts
- Comprehensive token information
swapTransactions.ts
- Transaction history
Essential Hooks
useFetchTokens()
Fetches all fungible tokens in a user’s wallet with portfolio data.
Returns:
tokens
- Array of user’s tokensloading
- Loading stateerror
- Error message if anyrefetch
- Function to refresh data
useTokenDetails()
Comprehensive token information for detail views.
Parameters:
tokenAddress
- Token mint addressvisible
- Whether to actively fetch data
Returns:
priceHistory
- Historical price datametadata
- Token metadatatokenOverview
- Overview informationloading
- Loading statesselectedTimeframe
- Current timeframehandleTimeframeChange
- Timeframe selector
useCoingecko()
Access CoinGecko market data with caching.
useTokenSearch()
Debounced token search with pagination.
Quick Start Example
Utility Functions
Data Sources Integration
Helius
Primary Use: RPC calls, transaction history, asset fetching
- Enhanced Solana RPC
- Transaction parsing
- Asset metadata
Birdeye
Primary Use: Token prices, security analysis, market data
- Real-time prices
- Security scoring
- Trade data
- Price history
CoinGecko
Primary Use: Market information, coin listings
- Coin directories
- Market cap data
- OHLC data
- Global statistics
Advanced Usage Patterns
Custom Data Fetching
Batch Data Operations
Real-time Price Updates
Error Handling
API Rate Limits: Be mindful of rate limits when making frequent requests. The module includes retry logic but respect provider limits.
Performance Optimization
Caching: The module implements intelligent caching for CoinGecko data and token metadata to reduce API calls.
Integration with Other Modules
With Wallet Providers
With Swap Module
Troubleshooting
API Reference
For detailed API documentation, see:
The Data Module serves as the foundation for all blockchain data needs in your Solana application, providing reliable, cached, and efficiently formatted data from multiple sources.