Skip to main content
Info Crypto uses the CoinGecko public API as its primary data source. It powers the Home page market overview, the Converter page live prices, and the Charts page historical data — all without requiring an API key.
The CoinGecko free tier enforces a rate limit of 30 calls per minute. The app uses localStorage caching with a 5-minute TTL to stay well within this limit under normal usage, but heavy manual refreshing can still trigger 429 responses.
No API key is required for the public demo endpoints used in this project. If you deploy to production and need higher throughput, consider upgrading to a CoinGecko paid plan and adding an x-cg-demo-api-key header to each request.

Endpoints

Top cryptocurrencies by market cap

Returns a ranked list of coins ordered by market capitalisation. Used by the Home page to display the top 20 cryptocurrencies.Source file: src/services/cryptoApi.jsgetTopCryptos()
GET https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=20&page=1

Query parameters

query.vs_currency
string
default:"usd"
required
The target currency for all price and market cap values. Set to usd.
query.order
string
default:"market_cap_desc"
Sort order for results. market_cap_desc returns coins from largest to smallest market cap.
query.per_page
number
default:"20"
Number of coins returned per page. Fixed at 20 in this integration.
query.page
number
default:"1"
Page number for pagination. Fixed at 1 — only the first page is fetched.

Source code

src/services/cryptoApi.js
export async function getTopCryptos() {
  try {
    const response = await fetch(
      "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=20&page=1"
    );
    const data = await response.json();
    return data;
  } catch (error) {
    console.error("Error fetching cryptos:", error);
    throw error;
  }
}

Cache key

KeyTTL
getInfoCrypto5 minutes
The cache helper keepInfo() in src/services/cache.js reads getInfoCrypto from localStorage and skips the network request if the cached value is less than 5 minutes old.

Response shape

Returns an array of coin objects.
[]\.id
string
required
Unique CoinGecko coin identifier (e.g. "bitcoin").
[]\.symbol
string
required
Ticker symbol in lowercase (e.g. "btc").
[]\.name
string
required
Human-readable coin name (e.g. "Bitcoin").
[]\.image
string
required
URL to the coin logo image.
[]\.current_price
number
required
Current price in USD.
[]\.market_cap
number
required
Total market capitalisation in USD.
[]\.total_volume
number
required
24-hour trading volume in USD.
[]\.price_change_percentage_24h
number
required
Percentage price change over the last 24 hours. Negative values indicate a decline.

Example response

[
  {
    "id": "bitcoin",
    "symbol": "btc",
    "name": "Bitcoin",
    "image": "https://assets.coingecko.com/coins/images/1/large/bitcoin.png",
    "current_price": 67423.00,
    "market_cap": 1327000000000,
    "total_volume": 28500000000,
    "price_change_percentage_24h": 2.34
  }
]

Caching strategy

All CoinGecko calls are wrapped in cache helpers defined in src/services/cache.js. Each helper reads from localStorage first and only makes a network request when the cached value is missing or older than 5 minutes.
src/services/cache.js
export async function keepInfo() {
  const cache = localStorage.getItem("getInfoCrypto");
  const cacheDate = localStorage.getItem("getInfoCryptoDate");

  if (cache && cacheDate && Date.now() - Number(cacheDate) < 5 * 60 * 1000) {
    return JSON.parse(cache);
  } else {
    const data = await getTopCryptos();
    localStorage.setItem("getInfoCrypto", JSON.stringify(data));
    localStorage.setItem("getInfoCryptoDate", Date.now());
    return data;
  }
}
The same pattern is used by keepPrice() and keepHistory() for the other two endpoints.
Cache helperlocalStorage keyEndpoint
keepInfo()getInfoCrypto/coins/markets
keepPrice()getPriceCrypto/simple/price
keepHistory(cryptoId, days)history_${cryptoId}_${days}/coins/{id}/market_chart

Build docs developers (and LLMs) love