CryptoApiResponse Interface
TheCryptoApiResponse interface represents the raw data structure returned by the CoinLore API for each cryptocurrency.
src/models/Crypto.ts
Fields
Unique identifier for the cryptocurrency
Trading symbol (e.g., “BTC”, “ETH”, “ADA”)
Full name of the cryptocurrency (e.g., “Bitcoin”, “Ethereum”)
URL-safe name identifier used for routing
Market cap ranking position (1 for Bitcoin, 2 for Ethereum, etc.)
Current price in US dollars (stored as string for precision)
Percentage price change over the last 24 hours
Percentage price change over the last hour
Percentage price change over the last 7 days
Price expressed in Bitcoin (BTC)
Total market capitalization in US dollars
Trading volume over the last 24 hours
Adjusted trading volume over the last 24 hours
Circulating supply of the cryptocurrency
Total supply of the cryptocurrency
Maximum supply of the cryptocurrency
Crypto Class
TheCrypto class provides an object-oriented wrapper around cryptocurrency data with additional utility methods.
src/models/Crypto.ts
Constructor Parameters
Unique identifier for the cryptocurrency
Full name of the cryptocurrency
Market cap ranking position
Trading symbol
Current price in US dollars
24-hour percentage price change
Methods
Getter that returns the price formatted as a currency string with 2 decimal places and a dollar sign prefix.Example:
"$45678.90"Usage Examples
Using CryptoApiResponse
The raw API response is typically used in services and hooks:src/hooks/useCryptoData.ts
Using Crypto Class
The Crypto class is instantiated when transforming API data:src/hooks/useCryptoData.ts
Accessing formattedPrice
Component Usage
src/components/CryptoCard.tsx
Type Safety
All string-based numeric fields (
price_usd, percent_change_24h, etc.) must be parsed to numbers before performing calculations. Always use parseFloat() and provide default values to handle edge cases.Related
Crypto Service
API functions for fetching cryptocurrency data
useCryptoData Hook
React hook for managing crypto data state