blockscout / blockscout-rs

Microservices for blockscout indexer
MIT License
156 stars 109 forks source link

Use CoinGecko API for fetching token images #609

Open vbaranov opened 1 year ago

vbaranov commented 1 year ago

CoinGecko's /coins/${symbol} api endpoint allows to fetch token images. Thus, if this endpoints responds on token's symbol and bundle {platform id, contract address} matches, we can fetch token image. We need also to make sure, that this fetching works slowly enough in order to prevent exceeding free/paid plan limits. I also suppose this should work as an extension of existing approach with fetching token icons from TrustWallet repo.

atapin commented 1 year ago

@vbaranov CoinGecko API's /coins/:id endpoint operates with some internal identifier of a coin. Often these ids have unobvious values, e.g. immutable-x for Immutable IMX or havven for Synthetix Network SNX token (holds 58th position in top-100 tokens by market cap).

I'd suggest fetching the icon via https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=1000&page=1 call and match the icon by token symbol. This endpoint returns the list of:

{
  "id": "bitcoin",
  "symbol": "btc",
  "name": "Bitcoin",
  "image": "https://assets.coingecko.com/coins/images/1/large/bitcoin.png?1547033579",
  ...
}

Also it's seems pragmatic to prefetch the icons and store and serve them as static assets via script. Especially for somewhat top500/top1000 coins. Does it make sense? In this case, the code fetching from TrustWallet repo can be removed.

Not closely related to this ticket, but are there plans to split chain.ex files to smaller and better defined chunks of functionality? ATM it looks very scary (almost 7k lines)