[ad_1]
Do you know that you need to use the Ethereum worth API from Moralis (a.okay.a. Token API) to get the worth of any ERC-20 token with only a few strains of code? All you want is a single name to the Ethereum worth API’s ”getTokenPrice” endpoint whereas passing a sequence and token handle as parameters:
const response = await Moralis.EvmApi.token.getTokenPrice({
handle,
chain,
});
By familiarizing your self with the Moralis Ethereum worth API and the ”getTokenPrice” endpoint, it is possible for you to to include this performance into all future Web3 tasks. All you might want to do is enroll with Moralis to leverage the complete energy of blockchain know-how right away!
Overview
In at the moment’s article, we are going to discover the perfect Ethereum worth API and learn to use this device to get token costs. To start with, we are going to kickstart this tutorial by briefly masking how one can get began with the Ethereum worth API from Moralis free of charge. From there, we offer a sensible instance of how the API works by exhibiting you how one can get the worth of any token in simply three steps:
Establishing MoralisCalling the ”getTokenPrice” endpointRunning the script
As soon as you understand how to get the worth of any token utilizing the Ethereum Value API, we are going to discover this interface’s capabilities additional. Lastly, to high issues off, we are going to evaluate the perfect Ethereum worth API with some options provided by varied opponents of Moralis. Observe that the Moralis ”Ethereum worth API” and ”Token API” are used synonymously on this article.
By following alongside, you’ll at first familiarize your self with the Moralis Ethereum worth API. Nonetheless, if you’re critical about stepping into the Web3 area, you need to know that Moralis provides extra blockchain growth assets.
As an illustration, an ideal instance is the testnet faucet web page, providing an inventory of the perfect crypto taps obtainable. The checklist incorporates a Fantom testnet faucet, a Sepolia testnet faucet, the perfect Ethereum faucet, a BNB faucet, an Aptos testnet faucet, and plenty of others!
What’s extra, do you know that you may entry the Ethereum worth API and some other instruments from Moralis totally free of charge? All you might want to do is enroll with Moralis, and you’ll instantly leverage the ability of blockchain know-how to construct smarter and sooner!
If you’re unfamiliar with APIs or have to refreshen your reminiscence, you could find a piece earlier than the abstract answering the ”what are APIs?” query.
Get Began with the Ethereum Value API for Free
With the enterprise-grade Ethereum worth API, you’ll be able to seamlessly combine real-time worth and token knowledge into your functions with a few strains of code. What’s extra, do you know you’ll be able to entry this glorious software programming interface totally free of charge?
To make use of the Ethereum worth API in your growth endeavors, all you want is a Web3 API key to name the interface’s varied endpoints. You may get your very personal key by signing up with Moralis!
Not solely does the Web3 API key present entry to the perfect token worth API but in addition to the entire Web3 APIs from Moralis. As such, by registering with Moralis, you may also use the Moralis Streams API and the Moralis Authentication API, for instance!
However, with an account at your disposal, you could find your key by logging in to the Moralis admin panel and navigating to the ”Web3 APIs” tab:
With this key, now you can name the Ethereum worth API’s varied endpoints. For a sensible instance of how this works, be a part of us within the subsequent part as we showcase the Ethereum worth API in motion by demonstrating how one can get any token worth!
Tips on how to Get Token Costs Utilizing the Ethereum Value API
This a part of the article will display how one can get token costs utilizing the Moralis Ethereum worth API. Additionally, the tutorial is split into the next three sections:
Establishing MoralisCalling the ”getTokenPrice” endpointRunning the script
By finishing the steps above, you’ll learn to seamlessly get the worth of any ERC-20 token very quickly! If this sounds thrilling, be a part of us within the following subsections as we cowl every step intimately!
Stipulations
Earlier than leaping into step one of this Ethereum worth API tutorial, you will want to take care of a few conditions:
Set up NodeJS v.14+ or PythonInstall npm/Yarn or pip
Relying in your preferences, you might want to set up NodeJS or Python and npm/Yarn or pip. The Ethereum worth API is appropriate with both of those choices. Nonetheless, for the rest of this tutorial, we are going to use NodeJS and npm to display how one can get token costs.
Step 1: Setting Up Moralis
If in case you have not already, the very first thing you might want to do is enroll with Moralis. Creating an account is free and solely takes a few seconds!
With an account at hand, you could additionally set up the Moralis SDK in your NodeJS challenge. To take action, open a brand new terminal and run the next command:
npm set up moralis @moralisweb3/common-evm-utils
Step 2: Calling the ”getTokenPrice” Endpoint
Now that you simply’ve arrange Moralis, the subsequent step is to create the script for calling the ”getTokenPrice” endpoint. As such, copy and enter the next code snippet into your ”index.js” file:
const Moralis = require(‘moralis’).default;
const { EvmChain } = require(‘@moralisweb3/common-evm-utils’);
const runApp = async () => {
await Moralis.begin({
apiKey: “YOUR_API_KEY”,
// …and some other configuration
});
const handle=”0x2260fac5e5542a773aa44fbcfedf7c193bc2c599″;
const chain = EvmChain.ETHEREUM;
const response = await Moralis.EvmApi.token.getTokenPrice({
handle,
chain,
});
console.log(response.toJSON());
}
runApp();
Within the snippet above, we name the ”getTokenPrice” endpoint whereas passing two parameters as arguments: ”handle” and ”chain”. Which means you might want to configure these two variables by including the token handle you want to question and deciding on the right chain:
Together with configuring these two variables, you could exchange ”YOUR_API_KEY” together with your precise key. You can find your key by logging in to the Moralis admin panel and navigating to the ”Web3 APIs” tab:
Step 3: Operating the Script
As soon as you might be achieved configuring the code, the very last thing that is still is working the script. To take action, ”cd” into the challenge’s root folder and run the next command:
node index.js
Consequently, you need to see a JSON response in your terminal trying one thing like this:
{
“nativePrice”: {
“worth”: “13753134139373781549”,
“decimals”: 18,
“title”: “Ether”,
“image”: “ETH”
},
“usdPrice”: 16115.165641767926,
“exchangeAddress”: “0x1f98431c8ad98523631ae4a59f267346ea31f984”,
“exchangeName”: “Uniswap v3”
}
Congratulations! You simply used the Ethereum worth API to get the worth of a token with only a few strains of code!
If you wish to see the ”getTokenPrice” endpoint in motion additional, you may also try the clip beneath from the Moralis YouTube channel. On this video, considered one of our gifted software program engineers makes use of the Ethereum worth API to create an entire software for getting the worth of any ERC-20 token:
Exploring the Main Value API for Ethereum
With the enterprise-grade Ethereum worth API from Moralis, you’ll be able to seamlessly combine real-time worth and token knowledge into your functions very quickly. This consists of worth, switch, and possession knowledge throughout all vital blockchain networks!
Listed here are three outstanding options of the main Ethereum worth API:
Token Costs – With the Ethereum worth API, you’ll be able to simply question any token’s worth at any given time. Moralis accumulates costs from AMMs corresponding to Uniswap and PancakeSwap, making them obtainable by way of simple API calls. Token Balances – By way of the Moralis Ethereum worth API, you’ll be able to seamlessly get the token stability of a consumer with a single API name. Token Transfers – Keep updated with essentially the most related and up to date token transfers utilizing the Ethereum worth API. With this programming interface, you’ll be able to fetch the switch historical past of a token or pockets and comply with them in real-time!
What’s extra, the Ethereum worth API is extremely versatile. For instance, this device helps all kinds of use instances, corresponding to:
Portfolio appsTransaction monitoringLive worth feedsOwnership verification
Additionally, the APIs from Moralis characteristic full cross-chain help, which means you do not want to fret about cross-chain compatibility. As a substitute, you need to use the identical APIs to construct functions throughout a number of chains with Moralis. Some outstanding examples are Ethereum, BNB Chain, Polygon, Avalanche, Solana, and plenty of extra!
Should you, for example, are occupied with Solana blockchain app growth, be certain to additionally try the Solana Python API!
Rivals
To raised perceive why the Moralis Token API is the most suitable choice available on the market for querying the worth of Ethereum tokens, allow us to take a more in-depth have a look at a few opponents. Two of Moralis’ closest and most outstanding opponents are Alchemy and QuickNode, each of which provide their very own token APIs.
As such, let’s discover these options additional to see how they differ from Moralis. To take action, permit us to start by briefly summarizing the principle capabilities and endpoints of every API within the desk beneath:
Because the desk above illustrates, all three options have so much to supply. Based mostly on the variety of endpoints and different points, which of the three is the perfect API for crypto costs? If you’d like the reply to this query, be a part of us within the subsequent part, the place we dive deeper into the variations between these choices!
What’s the Greatest API for Crypto Costs?
By rapidly glancing over the desk within the part above, you’ll instantly discover that solely Moralis provides an endpoint for fetching the worth of an ERC-20 token. As such, the simple reply to the ”what’s the greatest API for crypto costs?” query is the Moralis Ethereum worth API! Nonetheless, the extra attention-grabbing query is to check the three APIs total!
Initially, in relation to the variety of endpoints, Moralis outperforms each Alchemy and QuickNode. As such, Moralis provides extra performance in comparison with a few of its most outstanding opponents!
After doing a bit extra digging, we additionally got here to the conclusion that Moralis provides essentially the most complete cross-chain help. Which means the Token API from Moralis helps extra networks than the competitors.
That mentioned, it doesn’t imply that Alchemy and QuickNode are unhealthy choices for fetching token-related knowledge. Nonetheless, Moralis gives every little thing they’ve to supply and extra. As such, if you’re on the lookout for a complete Ethereum worth API, your final selection is Moralis!
If you’re on the lookout for extra articles on how one can combine token knowledge, you could find extra guides right here on the weblog. As an illustration, learn to get token metadata, get the token stability of an handle, or get all tokens owned by a pockets!
What are APIs?
In at the moment’s interconnected world, cross-system communication is significant to internet and software growth. Purposes and platforms don’t work optimally in isolation, so builders want environment friendly methods to allow software program techniques to speak. That is the place software programming interfaces (APIs) enter the equation!
When shopping the online or utilizing an software, your system connects to the web to ship directions to a server or database. From there, the receiving finish takes within the knowledge, interprets it, finds the suitable response(s), and returns it to your system. Subsequent, your system handles the response and presents the info in a readable format.
An API typically facilitates this course of, enabling two separate techniques to speak. These interfaces accomplish this by translating directions for mutual understanding and delivering features reliably on queries. Furthermore, this additionally permits appropriate coding in safe and secure environments, contributing to a extra accessible developer expertise!
That briefly covers the ins and outs of APIs. If you wish to know extra about APIs, try our article exploring Web3 APIs in additional element!
Abstract – The #1 Ethereum Value API
On this article, you bought to discover the intricacies of the Ethereum worth API from Moralis and why that is the most suitable choice available on the market. In doing so, we supplied a fast instance of how the API works in observe by exhibiting you how one can get the worth of any ERC-20 token. All you actually wanted was a single API name to the ”getTokenPrice” endpoint:
const response = await Moralis.EvmApi.token.getTokenPrice({
handle,
chain,
});
Should you discovered this tutorial useful, try extra blockchain growth content material right here on the Web3 weblog. For instance, examine Avalanche’s Fuji testnet, how one can use a Goerli faucet, or discover the perfect Notify API options!
What’s extra, if you’re occupied with starting your Web3 journey, be certain to take a look at Moralis Academy. The academy provides a choice of blockchain growth programs for skilled and new builders. As such, that is the perfect place to kickstart your Web3 growth journey. For instance, study in regards to the fundamentals of the trade by enrolling within the ”Ethereum 101” course.
Additionally, keep in mind to enroll with Moralis if you wish to entry the perfect Ethereum worth API, together with different enterprise blockchain options. In doing so, you’ll be able to leverage the complete potential of blockchain know-how to construct functions sooner and smarter!
[ad_2]
Source link