• Tue. Jul 2nd, 2024

Creating an Ethereum dApp with Crypto Price Data

How to create an ethereum dApp with crypto API - CoinGecko API

Digital applications that run on a blockchain network of computers, otherwise known as decentralized applications (dApps), provide users with innovative solutions that prioritize transparency, security and user control. According to DappRadar’s 2022 Industry Report, the dApp industry experienced a 50% increase in daily unique active wallets (dUAW), rising from 1.58 million dUAW to 2.37 million in 2022.

A key component of dApps is the ability to display real-time token price data, which empowers users to make informed decisions and engage with dynamic features seamlessly. In this guide, we will explore:

  • Common challenges developers face when integrating crypto data into dApps
  • Things to look out for when integrating crypto data
  • Popular CoinGecko API endpoints that developers use

Let’s dive in!

This guide caters to Ethereum-based web applications and ERC-20 tokens.


Common Challenges with Crypto Data Integrations

From navigating poorly documented APIs to facing data discrepancies, the developer community may face the following challenges when it comes to finding a crypto API provider.

  1. Unorganized Data that Lacks Comprehensive Token Coverage
    In terms of token data available, some crypto API providers may lack comprehensive price data covering a wide range of ERC-20 tokens. Beyond prices, dApps often require a comprehensive set of data, including historical price trends, trading volumes, market capitalization, and more. Sourcing and organizing this data from various providers and across multiple exchanges can be time-consuming and challenging, especially for developers who want to focus on innovation.

    Having poorly organized data where symbols clash can also mean that token ID mapping becomes a hassle for developers. For example, the BAT token can refer to Basic Attention Token or Batcoin, and WorldCoin (WDC) can be easily mixed up with Sam Altman’s Worldcoin (WLD). When symbols clash, developers end up spending time maintaining a list of tokens with the API provider ID or identifier, ultimately resulting in extra work or maintenance.

  2. Data Inconsistencies
    Developers may sometimes encounter inconsistent data when pulling crypto prices across various sources. Price disparities can lead to inaccurate token prices, which may then compromise dApp functionality. Another potential scenario that results in data discrepancies occur when the API data provider does not actively maintain its database or keep up with the evolving crypto market.

  3. Getting Rate Limited by Free or Public APIs
    Getting rate limited can hinder a dApp’s performance, leading to delays and potential disruptions in user experience. Developers may struggle to manage these especially if free, public APIs with a low rate limit are used to power dApps, and instead of reaping cost savings, this may instead result in a more resource-intensive processes, or a dApp that displays inconsistent or inaccurate crypto price data.

  4. Poorly Documented APIs and/or a Lack of Client Support
    Finally, a significant challenge developers encounter when integrating crypto data into dApps is the quality of API documentation and the availability of client support. Inadequate or confusing documentation can slow down the development process, leading to wasted time deciphering endpoints, parameters, and authentication methods. Further, a lack of responsive client support can leave developers stranded when they encounter issues or have questions about specific endpoints, their API usage and plan, and even accidental overages.

Selecting the Right Crypto API: Considerations to Note

Integrating real-time crypto price data into your dApp offers immense value – yet, as the above illustrates, it’s not without its challenges. Here are some key considerations to keep in mind, when assessing and selecting the right crypto API to leverage for your dApp.

  1. Data Coverage
    The crypto market evolves rapidly, which means that having comprehensive data coverage is essential when assessing a data provider for your dApp. Select a data provider that offers extensive coverage across a wide range of tokens (including ERC-20 tokens), and that continuously updates with new tokens listed, to ensure your dApp always remains relevant.

  2. Data Consistency and Accuracy
    Cryptocurrency markets can be highly volatile, and even slight discrepancies in prices across exchanges can lead to misinformation within your dApp. When selecting a crypto data provider, prioritize those with a proven track record of accurate data aggregation from multiple exchanges, and one that supplies high quality price data, such as CoinGecko API. Always thoroughly test and validate the data before incorporating it into your dApp, to ensure data integrity.

  3. Reliable API Uptime & Maintenance Logs
    Uninterrupted access to real-time price data is crucial for the smooth functioning of your dApp. Check the API provider’s historical uptime and downtime records. A reliable data provider will be transparent about its API status, and provide a comprehensive log of incidents and maintenance history. Ensuring that you onboard a robust and reliable API will minimize disruptions to your dApp’s user experience, and ensure that your users always have access to the latest price information.

  4. API Rate Limits and Scaling
    As your dApp gains in traction, the demand for real-time data may increase significantly. Be mindful of rate limits imposed by respective API providers. Exceeding these limits can result in temporary data unavailability or overage charges. Implementing caching mechanisms—temporarily storing data that your dApp frequently uses for quick retrieval (without having to refresh from the original source every single time)—for specific endpoints can help you stay within rate limits. Additionally, it’s important to plan ahead when it comes to scaling your dApp’s infrastructure to accommodate increased usage.

  5. User Privacy and Security
    Integrating external APIs, including crypto price data providers, may introduce potential security vulnerabilities. Ensure that the data provider follows industry best practices for data encryption, authentication, and privacy. Safeguard user data by adhering to data protection regulations and implementing proper security measures within your dApp.

  6. API Documentation and Support
    Thoroughly review the API documentation before integration – clear, comprehensive documentation will streamline the integration process and reduce development time. Look for well-documented code examples and use cases that match your dApp’s requirements. Additionally, assess the availability of client support. Prompt and knowledgeable support can be invaluable to developers, especially when faced with technical challenges during the integration process. A well-documented API combined with a responsive client support service are positive signals that the API is well-maintained.

  7. API Cost and Sustainability
    Lastly, consider the cost implications of integrating real-time price data into your dApp. Some API providers offer free access up to a certain limit, while others may require payment for higher usage tiers. Evaluate your dApp’s projected usage and growth to determine a sustainable pricing model. Factor in costs associated with potential upgrades, scaling, ongoing maintenance, as well as overages should rate limits exceed.

Popular CoinGecko API Endpoints for Ethereum dApps

To date, CoinGecko API has 50+ endpoints, tracks 10,000+ coins across 700+ exchanges and 3,000+ NFT collections – serving billions of API calls each month. We’ve listed the top 5 most popular CoinGecko API endpoints commonly used by developers and crypto projects, plus two bonus ones below, that you may want to consider for your next dApp:

Retrieve Live Token Prices with /coins/{id}

The /coins/{id} endpoint is especially useful to pull coin price and market data, exchange tickers, and metadata like links, categories, contract address, community, description, developer data and more, for specific coins. For example, the following Request URL can be used to retrieve live Bitcoin (BTC) price and metadata.

https://api.coingecko.com/api/v3/coins/bitcoin

 

Retrieve Historical Token Prices with /coins/{id}/history

/coins/{id}/history is a commonly used endpoint to get historical data (price, market cap, 24 hour volume etc.) at any given date, for a specific cryptocurrency. For example, the following Request URL can be used to retrieve historical Bitcoin (BTC) price and metadata on November 9, 2021.

https://api.coingecko.com/api/v3/coins/bitcoin/history?date=09-11-2021

 

Retrieve Latest Coins Listed with /coins/list/new

 /coins/list/new is the most efficient endpoint that returns the latest 200 coins’ ids and activated time as listed on CoinGecko. With a data update frequency or cache of 30s, this is an exclusive endpoint for Paid API subscribers. Its equivalent page on CoinGecko is New Cryptocurrencies. The Request URL is:

https://pro-api.coingecko.com/api/v3/coins/list/new?&x_cg_pro_api_key={YOUR-API-KEY}

 

Identify Trading Pairs (Tickers) with /coins/{id}/tickers

This endpoint identifies all trading pairs, also known as tickers, for a coin. Should you want to narrow this down to trading pairs on a specific exchange, centralized or decentralized, you may use coins/{id}/tickers or /exchanges/{id}/tickers and insert the right parameters to filter accordingly. For instance:

This Request URL returns all trading pairs for Ripple (XRP):

https://api.coingecko.com/api/v3/coins/ripple/tickers

This Request URL returns all trading pairs for Ripple on Binance:

https://api.coingecko.com/api/v3/coins/ripple/tickers?exchange_ids=binance

Alternatively, this Request URL also returns all trading pairs for Ripple on Binance:

https://api.coingecko.com/api/v3/exchanges/binance/tickers?coin_ids=ripple

 

Retrieve a List of Coins in a Specific Category with /coins/markets

Crypto market rallies are often led by trending narratives, and these tokens are actively curated into Top Crypto Categories by the CoinGecko team. Updating the ‘category’ params for the /coins/markets endpoint will enable you to pull out all coins data within specific categories.

For example, this Request URL can be used to retrieve all token data that is classified under the ‘Layer 2’ category:

https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&category=layer-2&order=market_cap_desc&per_page=100&page=1&sparkline=false

Similarly, the following Request URL returns all tokens under the ‘Telegram Bots’ category:

https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&category=telegram-bots&order=market_cap_desc&per_page=100&page=1&sparkline=false

 

Bonus: Looking Up Coins by Contract Address

If you’re building an Ethereum wallet web interface and have a list of tokens with contract addresses, you can look up tokens’ contract addresses to display price data in your preferred currency – with the endpoint /coins/{id}/contract/{contract_address}.

For example, the Request URL to return coin details from Chainlink (LINK) token with the contract address of ‘0x514910771af9ca656af840dff83e8264ecf986ca’, would be:

https://api.coingecko.com/api/v3/coins/ethereum/contract/0x514910771af9ca656af840dff83e8264ecf986ca

 

Bonus: Retrieve Coins Data by Symbol or Contract Address

Last but not least, you may have a list of tokens and want to retrieve the market price for each token in the list. You can easily use the /search endpoint to look up coins via a symbol OR the /simple/token_price/{id} endpoint to get the current price of tokens for a given platform, in any supported currency.

The Request URL using the /search endpoint, for Bitcoin (BTC) is:

https://api.coingecko.com/api/v3/search?query=btc

Here, we use the /simple/token_price/{id} endpoint where contract address is ‘0x514910771af9ca656af840dff83e8264ecf986ca’ (LINK) and currency is USD:

https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=0x514910771af9ca656af840dff83e8264ecf986ca&vs_currencies=usd

 


CoinGecko’s Paid API Plans

If you’re a developer or founder in the midst of building your dApp, you may want to consider getting in touch with our API sales team to enquire about the best API plan that would suit your needs. Fill in the form below to get in touch: