Coins: 14,784
Exchanges: 1,138
Market Cap: $2.468T 0.2%
24h Vol: $34.107B
Gas: 3 GWEI
Go Ad-free
Guides
TABLE OF CONTENTS

3 steps to power your Ethereum app with token price data using an API

TM Lee -

Are you building an Ethereum-based web application and find yourself the need to display price data of ERC-20 tokens?

We know how difficult it is to not only find an API provider that has support for the token you are looking for, but something that works best for the use case of an Ethereum app.

Challenges of adding price data

Some of the difficulties we hear from the developer community are :-

  1. Breadth of tokens
    Does the API provide price data for most of the ERC-20 tokens out there?
  2. Clashing symbols
    For example BAT can be Basic Attention Token or Batcoin.
  3. Token ID mappings
    Due to problem (2), developers are forced to maintain a list of mapped tokens with the API provider ID or identifier. This results in extra work/maintenance (Note: Most API services including CoinGecko will have an internal ID to differentiate different tokens)
  4. API keys
    API keys can be a problem especially when a web front-end decentralized app needs to access market data.

We acknowledge these issues and think we have got something that can bring joy and happiness to your developmental work!

For one, CoinGecko has the broadest coverage of coin/token currently at over 5400+ at the time of writing.

And more importantly, the latest update of the CoinGecko API provides new endpoints allowing developers to query ERC-20 token price using contract address as a unique identifier.

Finally, the API is publicly accessible and this means there is no keys required and it is free to use.

Scenario A: Adding price data to an Ethereum Wallet

Let’s walk through an example of an Ethereum web application use case.

Say you are building an Ethereum wallet web interface and you have a list of known tokens or perhaps even allowing users to input custom token based on a token contract address.

It would be ideal to display price data in USD, ETH, BTC, or any other currencies alongside the token as additional information.

  1. Obtain the token address, for example Basic Attention Token (0x0d8775f648430679a709e98d2b0cb6250d2887ef)
  2. Call the CoinGecko API query coin by contract endpoint as follows https://api.coingecko.com/api/v3/coins/ethereum/contract/0x0d8775f648430679a709e98d2b0cb6250d2887ef
  3. Parse the JSON response and display the value.

We are done!

In addition to that, if you would like to display token historical price, you may call the endpoint https://api.coingecko.com/api/v3/coins/ethereum/contract/0x0d8775f648430679a709e98d2b0cb6250d2887ef/market_chart?vs_currency=usd&days=7

Scenario B: I have a huge list of tokens and I need the market price for each of them

You can use the simple/token_price API endpoint as follows

https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=0x0d8775f648430679a709e98d2b0cb6250d2887ef%2C0xe41d2489571d322189246dafa5ebde1f4699f498%2C0xf5dce57282a584d2746faf1593d3121fcac444dc&vs_currencies=usd

This queries the USD price of 3 tokens (0x, Compound DAI, and Basic Attention Token) in a single request!

 

TLDR

CoinGecko API will save you plenty of time!

  1. Easy to implement, no need to maintain a file to map IDs. Using contract address, you are guaranteed uniqueness.
  2. Comprehensiveness. With over X tokens on Ethereum tracked on CoinGecko, you are most likely to find what you need.
  3. Scale. Since all you need is a contract address, you can scale the solution across any number of tokens!

 

Get started!

Awesome Ethereum-based services such as Etherscan, Metamask, and MyEtherWallet are already integrating the CoinGecko API

The CoinGecko API is public, free to use and no need for an API key.

How about you give it a spin, and let us know what you make of it?

If you are interested to integrate data, we have a cryptocurrency API documentation and playground.

CoinGecko's Content Editorial Guidelines
CoinGecko’s content aims to demystify the crypto industry. While certain posts you see may be sponsored, we strive to uphold the highest standards of editorial quality and integrity, and do not publish any content that has not been vetted by our editors.
Learn more
Want to be the first to know about upcoming airdrops?
Subscribe to the CoinGecko Daily Newsletter!
Join 600,000+ crypto enthusiasts, traders, and degens in getting the latest crypto news, articles, videos, and reports by subscribing to our FREE newsletter.
Tell us how much you like this article!
TM Lee
TM Lee
TM Lee is the co-founder of CoinGecko. Purdue University CS 2012 Follow the author on Twitter @tmlee

Related Articles

Select Currency
Suggested Currencies
USD
US Dollar
IDR
Indonesian Rupiah
TWD
New Taiwan Dollar
EUR
Euro
KRW
South Korean Won
JPY
Japanese Yen
RUB
Russian Ruble
CNY
Chinese Yuan
Fiat Currencies
AED
United Arab Emirates Dirham
ARS
Argentine Peso
AUD
Australian Dollar
BDT
Bangladeshi Taka
BHD
Bahraini Dinar
BMD
Bermudian Dollar
BRL
Brazil Real
CAD
Canadian Dollar
CHF
Swiss Franc
CLP
Chilean Peso
CZK
Czech Koruna
DKK
Danish Krone
GBP
British Pound Sterling
GEL
Georgian Lari
HKD
Hong Kong Dollar
HUF
Hungarian Forint
ILS
Israeli New Shekel
INR
Indian Rupee
KWD
Kuwaiti Dinar
LKR
Sri Lankan Rupee
MMK
Burmese Kyat
MXN
Mexican Peso
MYR
Malaysian Ringgit
NGN
Nigerian Naira
NOK
Norwegian Krone
NZD
New Zealand Dollar
PHP
Philippine Peso
PKR
Pakistani Rupee
PLN
Polish Zloty
SAR
Saudi Riyal
SEK
Swedish Krona
SGD
Singapore Dollar
THB
Thai Baht
TRY
Turkish Lira
UAH
Ukrainian hryvnia
VEF
Venezuelan bolívar fuerte
VND
Vietnamese đồng
ZAR
South African Rand
XDR
IMF Special Drawing Rights
Cryptocurrencies
BTC
Bitcoin
ETH
Ether
LTC
Litecoin
BCH
Bitcoin Cash
BNB
Binance Coin
EOS
EOS
XRP
XRP
XLM
Lumens
LINK
Chainlink
DOT
Polkadot
YFI
Yearn.finance
Bitcoin Units
BITS
Bits
SATS
Satoshi
Commodities
XAG
Silver - Troy Ounce
XAU
Gold - Troy Ounce
Select Language
Popular Languages
EN
English
RU
Русский
DE
Deutsch
PL
język polski
ES
Español
VI
Tiếng việt
FR
Français
PT
Português
All Languages
AR
العربية
BG
български
CS
čeština
DA
dansk
EL
Ελληνικά
FI
suomen kieli
HE
עִבְרִית
HI
हिंदी
HR
hrvatski
HU
Magyar nyelv
ID
Bahasa Indonesia
IT
Italiano
JA
日本語
KO
한국어
LT
lietuvių kalba
NL
Nederlands
NO
norsk
RO
Limba română
SK
slovenský jazyk
SL
slovenski jezik
SV
Svenska
TH
ภาษาไทย
TR
Türkçe
UK
украї́нська мо́ва
ZH
简体中文
ZH-TW
繁體中文
Login to track your favorite coin easily 🚀
By continuing, you agree to CoinGecko Terms of Service and acknowledge you’ve read our Privacy Policy
or
Forgot your password?
Didn't receive confirmation instructions?
Resend confirmation instructions
IT'S FREE! Track your favorite coin easily with CoinGecko 🚀
By continuing, you agree to CoinGecko Terms of Service and acknowledge you’ve read our Privacy Policy
or
Password must contain at least 8 characters including 1 uppercase letter, 1 lowercase letter, 1 number, and 1 special character
Didn't receive confirmation instructions?
Resend confirmation instructions
Forgot your password?
You will receive an email with instructions on how to reset your password in a few minutes.
Resend confirmation instructions
You will receive an email with instructions for how to confirm your email address in a few minutes.
Get the CoinGecko app.
Scan this QR code to download the app now App QR Code Or check it out in the app stores
coingecko
Continue in app
Track prices in real-time
Open App