With Moralis’ enterprise-grade Token Value API, you’ll be able to simply question each the historic and present value of any token with a single API name. All you have to do is name the ”getTokenPrice” endpoint whereas passing a token tackle as a parameter:
const response = await Moralis.EvmApi.token.getTokenPrice({
tackle,
});
With little to no prior growth expertise and a few data of Moralis, you’ll be able to seamlessly incorporate the snippet above into your future blockchain initiatives to get the worth of any ERC20 token! Merely enroll with Moralis and get began straight away!
You may moreover take a look at 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 without doubt one of the most necessary elements of Web3 growth. Moreover, one piece of data required for nearly all decentralized functions (dapps) and different Web3 platforms is token costs. For instance, if you’re constructing a decentralized trade (DEX), you ideally need to show the present costs of tokens in USD to enhance the person expertise. Nonetheless, the large query is, how do you get the worth of any ERC20 token? The reply to this query is Moralis’ Token Value API!
As talked about, because of Moralis’ enterprise-grade Token Value API, you’ll be able to 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. Nonetheless, earlier than exploring this software 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 function for builders, we bounce into the principle subject and discover Moralis’ Token Value API. Lastly, to high issues off, we offer a short walkthrough of the way it works by offering a sensible instance.
If you’re already aware of the Token Value API, make sure that to take a look at further Moralis instruments. Furthermore, one of the best Web3 infrastructure supplier, Moralis, presents a collection of different Web3 APIs. This contains, for instance, the Web3 Streams API. With this instrument, you’ll be able to seamlessly stream blockchain knowledge into your initiatives by way of Moralis webhooks!
However, it doesn’t matter if you wish to use the Token Value API or different Moralis instruments; you continue to want an account. Thus, earlier than continuing, enroll with Moralis proper now to totally make the most of the facility of blockchain know-how!
What’s an API?
Earlier than diving into one of the best token value API, allow us to refresh our recollections by returning to fundamentals and exploring the intricacies of APIs normally. As such, if you’re already aware of what they’re, be happy to skip straight into the ”Exploring the Greatest Token Value 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 ”software programming interface”. Moreover, this growth instrument is accountable for facilitating communication between numerous items of software program. Consequently, as you’ll be able to think about, APIs play a vital function in each the Web2 and Web3 infrastructures.
When searching the web or interacting with apps, your gadget connects to the online 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 usually mediated by an API, translating a set of directions and enabling the 2 decoupled programs 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 slim the scope and discover the ins and outs of token value APIs!
What’s a Value API for Tokens?
Inside the Web3 area, a major a part of the event course of revolves round cross-system communications. So, since dapps and different initiatives are constructed on numerous blockchain networks, these programs want environment friendly methods to speak and work together. That is the place instruments reminiscent of token value APIs enter the equation!

As an illustration, let’s think about you need to construct a decentralized trade (DEX). On this trade, you need to allow customers to swap, promote, and buy blockchain tokens. Ideally, you need to show the present value of every token instantly in your software in order that customers know what they’re anticipated to pay.
To get this data, you need to question real-time knowledge instantly from the blockchain. Nonetheless, from a standard perspective, this has been fairly a problem. Happily for you, that is now not the case, as you’ll be able to simply entry token value APIs aiding on this course of!
Via a token value API, you’ll be able to seamlessly combine real-time token value knowledge into your dapps (decentralized functions) and different Web3 initiatives with solely a few traces of code. Nonetheless, which token value API do you have to go for? If you’d 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 Value API in 2023
One of the best API for buying the worth of tokens is Moralis’ Token API! With this instrument, you’ll be able to combine real-time token knowledge into your dapps with solely a few traces of code. Moreover, because of Moralis’ cross-chain capabilities, you should use this API for growth on a number of networks. This contains Ethereum, BNB Chain, Polygon, Avalanche, and plenty of extra!
TRUSTED BY INDUSTRY LEADERS

The Token API from Moralis has three key options:
Token Balances – With Moralis’ Token API, you’ll be able to seamlessly question all tokens customers maintain with a single API name. The interface options full historic assist, and you will get a person’s steadiness at any block quantity. Token Transfers – You may keep updated with the newest token transfers utilizing the API. As such, with Moralis, you’ll be able to 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 reminiscent of PancakeSwap and Uniswap, making them accessible in a single API name.
On this tutorial, we’ll give attention to the latter. As we accomplish that, we’ll briefly present you how one can get the worth of any ERC20 token. Furthermore, as we beforehand talked about, you will get the worth of any token by means of a single API name. That mentioned, to accumulate a token’s value, you have 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’re solely required so as to add an ”tackle” parameter to get the worth. Nonetheless, you may as well specify different parameters such because the ”chain”, ”trade”, and ”to_block”. So, allow us to break down what every parameter entails:
”tackle” – Add the tackle of the token you need to get the worth from.”chain” – Specify the chain you need to question. Should you exclude this parameter, the default choice is the Ethereum community. ”trade” – Choose a specific trade utilizing the manufacturing facility identify or tackle. ”to_block” – Specify the block quantity to find out from which block the token value must be queried.
When you full all of the fields of your alternative, you’ll be able to check out the endpoint instantly 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 may moreover change the programming language on the high if you want to know the way the ”getTokenPrice” endpoint works utilizing, as an illustration, Python:
However, that covers the important elements of the ”getTokenPrice” endpoint. Nonetheless, within the following part, we’ll present you how one can use the Moralis Token Value API to name the endpoint with a sensible instance!
Methods to Use Moralis’ Token Value API
Now that you’ve familiarized your self with Moralis’ Token Value API and the ”getTokenPrice” endpoint, this part briefly covers the intricacies of how this Moralis instrument works in observe. As such, we’ll rapidly present you how one can create a NodeJS mission enabling you to fetch the worth of any ERC20 token primarily based on its tackle!
To start with, open your built-in growth setting (IDE) and arrange a brand new NodeJS mission. 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 tackle=”0x1234567890123456789012345678901234567890″;
await Moralis.begin({
apiKey: ‘YOUR_API_KEY’,
// …and every other configuration
});
const response = await Moralis.EvmApi.token.getTokenPrice({
tackle,
chain,
});
console.log(response?.outcome);
} 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, you have to configure this variable if you’re seeking to question on-chain knowledge from every other community. Second, add the token tackle to the ”tackle” variable. Lastly, to high issues off, you have to substitute ”YOUR_API_KEY” with your personal Moralis API key.
To get the important thing, you have to have an lively Moralis account. As such, in case you have not already, be part of Moralis proper now! With an account at hand, yow will discover the important thing as you log in to the admin panel and click on on the ”Web3 APIs” tab:
As soon as you’re performed with the mandatory code configurations, all that is still is working this script. To take action, open a terminal, ”cd” into the mission’s root folder, and set up the Moralis dependencies with this command:
npm i moralis @moralisweb3/common-evm-utils
Lastly, you will need to run the script. To take action, enter the next and hit enter:
node index.js
In flip, you need to obtain a response in your console just like the one proven down under:
{
“nativePrice”: {
“worth”: “6797848427”,
“decimals”: 18,
“identify”: “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 instantly in your Web3 initiatives!
Utilizing Moralis’ Token Value API One Step Additional
Now that you understand how Moralis’ Token Value API works and might use this interface to name the ”getTokenPrice” endpoint, you’ll be able to apply the identical elementary ideas in your Web3 growth endeavors!
Nonetheless, if you need additional assist in doing so, or are searching for inspiration on your subsequent mission, take a look at the video down under from the Moralis YouTube channel. On this clip, one in all our proficient software program engineers reveals you how one can create an easy software using the Token Value API to fetch the worth of an ERC20 token primarily based on its tackle:
As well as, if you need additional particulars on how the ”getTokenPrice” endpoint works, take a look at Moralis’ official get ERC20 token value documentation web page!
The Greatest Token Value API – Abstract
With Moralis’ Token Value API, you’ll be able to question each the historic and present value of any ERC20 token. What’s extra, you are able to do so by means of a single API name. All you have to do is name the ”getTokenPrice” endpoint whereas passing the token tackle as a parameter:
const response = await Moralis.EvmApi.token.getTokenPrice({
tackle,
});
On this article, we explored the intricacies of the Token Value API, together with overlaying the way it works. In case you have adopted alongside till now, you understand how to create a NodeJS mission. Moreover, you understand how to implement the code wanted to question the worth of any ERC20 token!
Should you discovered this tutorial instructive, take a look at further articles right here at Moralis’ Web3 weblog. As an illustration, yow will discover two related guides on how one can get wallets native crypto steadiness or get the steadiness of ERC20 tokens from any tackle. We are able to additionally advocate our article on the last 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. As an illustration, take a look at the course on trade fundamentals: ”Blockchain & Bitcoin 101”.
However, you want an account if you wish to use the Moralis Token Value 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!