With Moralis’ enterprise-grade Token Worth API, you possibly can simply question each the historic and present value of any token with a single API name. All it’s good to do is name the ”getTokenPrice” endpoint whereas passing a token handle as a parameter:
const response = await Moralis.EvmApi.token.getTokenPrice({ handle, });
With little to no prior growth expertise and a few data of Moralis, you possibly can seamlessly incorporate the snippet above into your future blockchain initiatives to get the worth of any ERC20 token! Merely join with Moralis and get began immediately!

You possibly can moreover try the official get ERC20 token value documentation web page for extra details about the ins and outs of the ”getTokenPrice” endpoint.
Overview
Getting your fingers on real-time blockchain knowledge is likely one of the most vital elements of Web3 growth. Moreover, one piece of knowledge required for nearly all decentralized purposes (dapps) and different Web3 platforms is token costs. For instance, if you’re constructing a decentralized trade (DEX), you ideally wish to show the present costs of tokens in USD to enhance the consumer expertise. Nevertheless, the large query is, how do you get the worth of any ERC20 token? The reply to this query is Moralis’ Token Worth API!
As talked about, due to Moralis’ enterprise-grade Token Worth API, you possibly can seamlessly question the worth of any token with a single API name. If this sounds thrilling, be part of us all through this tutorial as we discover one of the best token value API and present you the way it works. Nevertheless, earlier than exploring this utility programming interface, we’ll kickstart this tutorial with a deep dive into APIs. After you have a greater understanding of what APIs are and why they play a major position for builders, we bounce into the principle matter and discover Moralis’ Token Worth API. Lastly, to prime issues off, we offer a short walkthrough of the way it works by offering a sensible instance.
In case you are already accustomed to the Token Worth API, be sure that to take a look at extra Moralis instruments. Furthermore, one of the best Web3 infrastructure supplier, Moralis, provides a number of different Web3 APIs. This contains, for instance, the Web3 Streams API. With this instrument, you possibly can seamlessly stream blockchain knowledge into your initiatives by way of Moralis webhooks!
However, it doesn’t matter if you wish to use the Token Worth API or different Moralis instruments; you continue to want an account. Thus, earlier than continuing, join with Moralis proper now to totally make the most of the ability of blockchain know-how!
What’s an API?
Earlier than diving into one of the best token value API, allow us to refresh our reminiscences by returning to fundamentals and exploring the intricacies of APIs normally. As such, if you’re already accustomed to what they’re, be happy to skip straight into the ”Exploring the Greatest Token Worth API in 2023” part. In any other case, be part of us right here as we reply the query, ”what’s an API?”.
API is an abbreviation for ”utility programming interface”. Moreover, this growth instrument is answerable for facilitating communication between varied items of software program. Consequently, as you possibly can think about, APIs play an important position in each the Web2 and Web3 infrastructures.
When shopping the web or interacting with apps, your gadget connects to the net and transmits knowledge to a server or database. In flip, the receiving finish interprets the knowledge, will get the suitable response, and sends it again to your gadget. From there, your gadget processes the info and presents it in a readable format.

The aforementioned course of is mostly mediated by an API, translating a set of directions and enabling the 2 decoupled methods to speak seamlessly. Furthermore, APIs guarantee appropriate coding in protected and safe growth environments, achieved by delivering features reliably on request. As such, APIs present a considerably extra accessible developer expertise.
So, now that you’ve a greater understanding of what an API is and why APIs are useful, allow us to get extra particular. Within the subsequent part, we’ll slender the scope and discover the ins and outs of token value APIs!
What’s a Worth API for Tokens?
Throughout the Web3 house, a major a part of the event course of revolves round cross-system communications. So, since dapps and different initiatives are constructed on varied blockchain networks, these methods want environment friendly methods to speak and work together. That is the place instruments corresponding to token value APIs enter the equation!

For example, let’s think about you wish to construct a decentralized trade (DEX). On this trade, you wish to allow customers to swap, promote, and buy blockchain tokens. Ideally, you wish to show the present value of every token straight in your utility in order that customers know what they’re anticipated to pay.
To get this data, you wish to question real-time knowledge straight from the blockchain. Nevertheless, from a traditional perspective, this has been fairly a problem. Luckily for you, that is now not the case, as you possibly can simply entry token value APIs aiding on this course of!
Via a token value API, you possibly can seamlessly combine real-time token value knowledge into your dapps (decentralized purposes) and different Web3 initiatives with solely a few strains of code. Nevertheless, which token value API must you go for? If you would like the reply to this query, be part of us as we discover one of the best token value API within the following part!
Exploring the Greatest Token Worth API in 2023
The very best API for buying the worth of tokens is Moralis’ Token API! With this instrument, you possibly can combine real-time token knowledge into your dapps with solely a few strains of code. Moreover, due to Moralis’ cross-chain capabilities, you need to use this API for growth on a number of networks. This contains Ethereum, BNB Chain, Polygon, Avalanche, and lots of extra!
TRUSTED BY INDUSTRY LEADERS

The Token API from Moralis has three key options:
- Token Balances – With Moralis’ Token API, you possibly can seamlessly question all tokens customers maintain with a single API name. The interface options full historic assist, and you may get a consumer’s stability at any block quantity.
- Token Transfers – You possibly can keep updated with the newest token transfers utilizing the API. As such, with Moralis, you possibly can see the switch historical past of a pockets or a specific token and observe them in actual time.
- Token Costs – The Token API aggregates token costs from AMMs corresponding to PancakeSwap and Uniswap, making them out there in a single API name.
On this tutorial, we’ll concentrate on the latter. As we achieve this, we’ll briefly present you how you can get the worth of any ERC20 token. Furthermore, as we beforehand talked about, you may get the worth of any token by way of a single API name. That stated, to amass a token’s value, it’s good to name the ”getTokenPrice” endpoint. However what precisely is that this endpoint, and the way does it work?
Moralis’ ”getTokenPrice” Endpoint
The ”getTokenPrice” endpoint is the important thing for querying the worth of any ERC20 token. As such, allow us to navigate to the get ERC20 token value documentation web page and examine the endpoint additional:

Because the picture above illustrates, you might be solely required so as to add an ”handle” parameter to get the worth. Nevertheless, you can even specify different parameters such because the ”chain”, ”trade”, and ”to_block”. So, allow us to break down what every parameter entails:
- ”handle” – Add the handle of the token you wish to get the worth from.
- ”chain” – Specify the chain you wish to question. When you exclude this parameter, the default choice is the Ethereum community.
- ”trade” – Choose a specific trade utilizing the manufacturing facility title or handle.
- ”to_block” – Specify the block quantity to find out from which block the token value ought to be queried.
When you full all of the fields of your selection, you possibly can check out the endpoint straight within the browser by clicking on ”Strive It!”. In doing so, you’ll instantly obtain a response within the ”RESPONSE” part. This lets you see what to anticipate in your code:

You possibly can moreover change the programming language on the prime if you need to know the way the ”getTokenPrice” endpoint works utilizing, for example, Python:
However, that covers the important elements of the ”getTokenPrice” endpoint. Nevertheless, within the following part, we’ll present you how you can use the Moralis Token Worth API to name the endpoint with a sensible instance!
How you can Use Moralis’ Token Worth API
Now that you’ve familiarized your self with Moralis’ Token Worth API and the ”getTokenPrice” endpoint, this part briefly covers the intricacies of how this Moralis instrument works in follow. As such, we’ll shortly present you how you can create a NodeJS challenge enabling you to fetch the worth of any ERC20 token primarily based on its handle!
To start with, open your built-in growth surroundings (IDE) and arrange a brand new NodeJS challenge. From there, create a brand new ”index.js” file and add the next contents:
import Moralis from 'moralis'; import { EvmChain } from '@moralisweb3/evm-utils'; attempt { const chain = EvmChain.ETHEREUM; const handle="0x1234567890123456789012345678901234567890"; await Moralis.begin({ apiKey: 'YOUR_API_KEY', // ...and every other configuration }); const response = await Moralis.EvmApi.token.getTokenPrice({ handle, chain, }); console.log(response?.end result); } catch (e) { console.error(e); }
Within the snippet above, there are three variables so that you can think about. By inspecting the code, you’ll discover that the ”chain” variable is about to ”EvmChain.ETHEREUM” by default. Consequently, it’s good to configure this variable if you’re trying to question on-chain knowledge from every other community. Second, add the token handle to the ”handle” variable. Lastly, to prime issues off, it’s good to substitute ”YOUR_API_KEY” with your individual Moralis API key.
To get the important thing, it’s good to have an energetic Moralis account. As such, when you’ve got not already, be part of Moralis proper now! With an account at hand, you’ll find the important thing as you log in to the admin panel and click on on the ”Web3 APIs” tab:
As soon as you might be performed with the mandatory code configurations, all that is still is operating this script. To take action, open a terminal, ”cd” into the challenge’s root folder, and set up the Moralis dependencies with this command:
npm i moralis @moralisweb3/common-evm-utils
Lastly, you have to run the script. To take action, enter the next and hit enter:
node index.js
In flip, you must obtain a response in your console much like the one proven down under:
{ "nativePrice": { "worth": "6797848427", "decimals": 18, "title": "Ether", "image": "ETH" }, "usdPrice": 0.000008253178821053, "exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984", "exchangeName": "Uniswap v3" }
One of many parameters within the response is the token’s value in USD. From right here, now you can simply use this knowledge straight in your Web3 initiatives!
Utilizing Moralis’ Token Worth API One Step Additional
Now that you know the way Moralis’ Token Worth API works and might use this interface to name the ”getTokenPrice” endpoint, you possibly can apply the identical elementary ideas in your Web3 growth endeavors!
Nevertheless, if you need additional assist in doing so, or are searching for inspiration in your subsequent challenge, try the video down under from the Moralis YouTube channel. On this clip, considered one of our proficient software program engineers exhibits you how you can create a simple utility using the Token Worth API to fetch the worth of an ERC20 token primarily based on its handle:
As well as, if you need additional particulars on how the ”getTokenPrice” endpoint works, try Moralis’ official get ERC20 token value documentation web page!
The Greatest Token Worth API – Abstract
With Moralis’ Token Worth API, you possibly can question each the historic and present value of any ERC20 token. What’s extra, you are able to do so by way of a single API name. All it’s good to do is name the ”getTokenPrice” endpoint whereas passing the token handle as a parameter:
const response = await Moralis.EvmApi.token.getTokenPrice({ handle, });
On this article, we explored the intricacies of the Token Worth API, together with protecting the way it works. If in case you have adopted alongside till now, you know the way to create a NodeJS challenge. Moreover, you know the way to implement the code wanted to question the worth of any ERC20 token!
When you discovered this tutorial instructive, try extra articles right here at Moralis’ Web3 weblog. For example, you’ll find two comparable guides on how you can get wallets native crypto stability or get the stability of ERC20 tokens from any handle. We are able to additionally suggest our article on the final word ERC20 token API!
Furthermore, think about becoming a member of Moralis Academy instantly if you wish to develop into a more adept Web3 developer. The academy provides wonderful blockchain programs for each new and skilled Web3 builders. For example, try the course on trade fundamentals: ”Blockchain & Bitcoin 101”.
However, you want an account if you wish to use the Moralis Token Worth API. As such, take your time now to enroll with Moralis. Creating an account is free and solely takes a few seconds; you’ll not remorse it!