Saturday, August 16, 2025
  • Login
SB Crypto Guru News- latest crypto news, NFTs, DEFI, Web3, Metaverse
No Result
View All Result
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • WEB3
  • METAVERSE
  • REGULATIONS
  • SCAM ALERT
  • ANALYSIS
CRYPTO MARKETCAP
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • WEB3
  • METAVERSE
  • REGULATIONS
  • SCAM ALERT
  • ANALYSIS
No Result
View All Result
SB Crypto Guru News- latest crypto news, NFTs, DEFI, Web3, Metaverse
No Result
View All Result

#1 API for Crypto Costs

by SB Crypto Guru News
October 17, 2023
in Web3
Reading Time: 16 mins read
0 0
A A
0


#1 API for Crypto Costs

At present’s article will present you tips on how to get any token’s real-time and historic costs utilizing one of the best API for crypto costs: the Moralis Worth API! All you want is a single API name to the getTokenPrice() endpoint whereas passing the token handle and chain as parameters: 

const response = await Moralis.EvmApi.token.getTokenPrice({
  "chain": "0x1",
  "handle": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
});

In return, you’ll get a response containing the token worth denominated in each the blockchain’s native foreign money and USD. Right here’s an instance of what it could possibly appear to be: 

{
  "tokenName": "Wrapped Ether",
  "tokenSymbol": "WETH",
  "tokenLogo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png",
  "tokenDecimals": "18",
  "nativePrice": {
    "worth": "1000000000000000000",
    "decimals": 18,
    "identify": "Ether",
    "image": "ETH",
    "handle": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
  },
  "usdPrice": 1549.8854069903737,
  "usdPriceFormatted": "1549.885406990373672051",
  "exchangeName": "Uniswap v3",
  "exchangeAddress": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
  "tokenAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
}

For a extra detailed tutorial on how this works, be part of us on this article or try the official get ERC-20 token worth documentation web page! 

If you wish to make comparable calls to the Worth API your self, don’t overlook to join an account with Moralis. You may be part of totally free and begin constructing Web3 initiatives quicker, smarter, and extra effectively! 

Table/graph showing pros and cons of various APIs for crypto prices

Overview

In at this time’s article, we’ll begin issues off by evaluating the Moralis Worth API to competing product choices. From there, we’ll take a more in-depth have a look at our Worth API and discover a few of its most distinguished options. Subsequent, we’re going to go extra in-depth with an in depth tutorial on tips on how to get the value of any cryptocurrencies utilizing one of the best API for crypto costs in three steps: 

  1. Get a Moralis API Key for Free
  2. Write a Script Calling the getTokenPrice() Endpoint
  3. Run the Code

What’s extra, we have now three sections in the direction of the tip of the information the place we return to fundamentals explaining the intricacies of crypto worth APIs, what to think about when selecting one, and what they’re used for. As such, should you’re new to the Web3 area, take into account beginning with the ”What’s an API for Crypto Costs, and How Does it Work?” part.

Along with the free API for crypto costs, Moralis gives extra superb merchandise price trying out should you’re severe about constructing blockchain initiatives. For example, discover one of the best Web3 Market Knowledge API or be taught concerning the #1 NFT picture API.

With the instruments above, it has by no means been simpler to construct Web3 initiatives. So, earlier than you proceed, bear in mind to enroll with Moralis, and also you’ll get free entry to one of the best API for crypto costs, amongst many different issues! 

Beat the Competitors Utilizing the Greatest API for Crypto Costs 

There are a number of crypto worth APIs so that you can select from; nonetheless, on the prime of the checklist, you’ll discover the Moralis Worth API!

Moralis Price API for crypto prices - Marketing material

Our Worth API is essentially the most complete API in the marketplace, masking every thing from the most recent and smallest cash to well-established cryptocurrencies like ETH. What’s extra, the Worth API helps all main EVM chains, integrating with main decentralized exchanges (DEXs) resembling Uniswap v3, Quickswap v2, PancakeSwap v3, and plenty of others.

Now, the massive query is, how does Moralis examine to the competitors? 

The Moralis Worth API stands out because the trade’s premier interface for crypto costs. You may choose any metric – whether or not you need to choose by pace, options, token protection, or aggressive pricing – our Worth API will all the time come out on prime! 

Be at liberty to match our API to distinguished opponents resembling CoinMarketCap, CoinGecko, or every other API for crypto costs obtainable in the marketplace:

Graph showing how Moralis Price API beats the competition like CoinGecko and CoinMarketCap Price APIs

When you’d prefer to be taught extra concerning the trade’s main API for crypto costs, be part of us within the subsequent part as we dive deeper into the Moralis Worth API! 

Discover the Moralis Worth API to Get Crypto Costs 

As an trade chief, the Moralis Worth API supplies you with every thing you want when it comes to crypto costs to construct subtle decentralized functions (dapps). With solely single strains of code, you possibly can effortlessly get the real-time worth of any crypto, fetch historic worth knowledge, and make batch requests! 

So, how does our Worth API work? 

Within the following subsections, we’ll spotlight the ability of the Worth API by exploring three distinguished options and the way they work. If this sounds thrilling, be part of us as we bounce straight into the primary instance and take a more in-depth have a look at the getTokenPrice() endpoint!

Get Actual-Time Costs 

With the Worth API, you possibly can seamlessly get real-time costs for any ERC-20 token with a single API name. All it’s important to do is choose a sequence, add the contract handle, and name the getTokenPrice() endpoint. Right here’s an instance of what it could possibly appear to be: 

const response = await Moralis.EvmApi.token.getTokenPrice({
  "chain": "0x1",
  "handle": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
});

In return for calling the endpoint above, you’ll get a response with the token’s worth denominated in each the blockchain’s native foreign money and USD:

{
  "tokenName": "Wrapped Ether",
  "tokenSymbol": "WETH",
  "tokenLogo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png",
  "tokenDecimals": "18",
  "nativePrice": {
    "worth": "1000000000000000000",
    "decimals": 18,
    "identify": "Ether",
    "image": "ETH",
    "handle": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
  },
  "usdPrice": 1549.8854069903737,
  "usdPriceFormatted": "1549.885406990373672051",
  "exchangeName": "Uniswap v3",
  "exchangeAddress": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
  "tokenAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
}

Fetch Historic Worth Knowledge 

The Worth API moreover lets you fetch historic costs for any cryptocurrencies. You merely have to name the getTokenPrice() endpoint whereas together with a toBlock parameter that specifies from which block you need to fetch the info. That is what it could possibly appear to be: 

const response = await Moralis.EvmApi.token.getTokenPrice({
  "chain": "0x1",
  "toBlock": 18085987,
  "handle": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
});

Calling the endpoint above gives you a response with the token’s historic worth on the time of the required block. Right here’s an instance of what it’d appear to be: 

{
  "tokenName": "Wrapped Ether",
  "tokenSymbol": "WETH",
  "tokenLogo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png",
  "tokenDecimals": "18",
  "nativePrice": {
    "worth": "1000000000000000000",
    "decimals": 18,
    "identify": "Ether",
    "image": "ETH",
    "handle": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
  },
  "usdPrice": 1631.86,
  "usdPriceFormatted": "1631.86",
  "exchangeName": "Uniswap v3",
  "exchangeAddress": "0x1F98431c8aD98523631AE4a59f267346ea31F984",
  "tokenAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
  "toBlock": "18085987"
}

Make Batch Requests 

Lastly, the Worth API additionally permits you to make batch requests for a number of tokens on the similar time. All it’s important to do is specify an array of the tokens you’re excited by, and that is an instance of what a request can appear to be:

// Dependencies to put in:
// $ npm set up node-fetch --save
// add "sort": "module" to package deal.json

import fetch from 'node-fetch';

const choices = {
  methodology: 'POST',
  headers: {
    settle for: 'utility/json',
    'content-type': 'utility/json',
    'X-API-Key': 'YOUR_API_KEY'
  },
  physique: JSON.stringify({
    "tokens": [
      {
        "token_address": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84"
      },
      {
        "token_address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
      }
    ]
  })
};

fetch('https://deep-index.moralis.io/api/v2.2/erc20/costs?chain=eth&embody=percent_change', choices)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

In return for operating the code above, you’ll get a response with an array of the tokens, and every factor could have the value denominated within the chain’s native foreign money and USD. Right here’s an instance of a response:

[
  {
    "tokenName": "stETH",
    "tokenSymbol": "stETH",
    "tokenLogo": "https://cdn.moralis.io/eth/0xae7ab96520de3a18e5e111b5eaab095312d7fe84.png",
    "tokenDecimals": "18",
    "nativePrice": {
      "value": "996102738724930500",
      "decimals": 18,
      "name": "Ether",
      "symbol": "ETH",
      "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
    },
    "usdPrice": 1541.8010573783215,
    "usdPriceFormatted": "1541.8010573783215",
    "24hrPercentChange": "-0.11200622701040466",
    "exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
    "exchangeName": "Uniswap v3",
    "tokenAddress": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84"
  },
  {
    "tokenName": "Wrapped Ether",
    "tokenSymbol": "WETH",
    "tokenLogo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png",
    "tokenDecimals": "18",
    "nativePrice": {
      "value": "1000000000000000000",
      "decimals": 18,
      "name": "Ether",
      "symbol": "ETH",
      "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
    },
    "usdPrice": 1547.833368425346,
    "usdPriceFormatted": "1547.833368425346",
    "24hrPercentChange": "-0.11200622701040529",
    "exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
    "exchangeName": "Uniswap v3",
    "tokenAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
  }
]

Observe: You can even make a batch request for historic worth knowledge. To take action, you simply want so as to add a to_block parameter for every token in your array. 

API for Crypto Costs: Tutorial 

On this part, we’ll dive a bit deeper into the #1 API for crypto costs and provide you with an in-depth tutorial on tips on how to get the value of any token. And because of the accessibility of our Worth API, you possibly can effortlessly get the info you want in three easy steps: 

  1. Get a Moralis API Key for Free
  2. Write a Script Calling the getTokenPrice() Endpoint
  3. Run the Code

Nevertheless, earlier than beginning the tutorial, you have to care for a couple of stipulations, which we’ll cowl within the following sub-section! 

API for Crypto Costs – Stipulations 

Our Worth API helps a number of programming languages, together with Python, JavaScript, and so forth. Nevertheless, on this tutorial, we’ll be utilizing JavaScript. For that reason, you should have the next prepared earlier than you possibly can proceed: 

Step 1: Get a Moralis API Key for Free 

To make calls to our Worth API, you require a Moralis API key. Consequently, the very first thing you should do is join with Moralis. So, should you haven’t already, click on on the ”Begin for Free” button on the prime proper and arrange your account: 

Start for Free using the Price API for crypto prices - Button on Landing page

Subsequent, head on over to the ”Settings” tab, scroll right down to the ”Secrets and techniques” part, and duplicate your key: 

Copying API key for crypto prices

Hold it for now, as you’ll want it within the subsequent part to initialize the Moralis SDK. 

Step 2: Write a Script Calling the getTokenPrice() Endpoint 

For the second step, begin by establishing a brand new challenge in your most well-liked built-in improvement setting (IDE), open a brand new terminal, and execute the next command to put in Moralis’ SDK: 

npm set up moralis @moralisweb3/common-evm-utils

Subsequent, create an ”index.js” file within the challenge’s root folder and add the next code: 

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async () => {
  await Moralis.begin({
    apiKey: "YOUR_API_KEY",
    // ...and every other configuration
  });

  const handle = "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599";

  const chain = EvmChain.ETHEREUM;

  const response = await Moralis.EvmApi.token.getTokenPrice({
    handle,
    chain,
  });

  console.log(response.toJSON());
};

runApp();

From right here, be sure that to interchange YOUR_API_KEY with the important thing you copied in step one to initialize the Moralis SDK: 

Pasting the API key into the code

You may then configure the handle and chain parameters to suit your explicit request: 

Configuring the address and chain parameters to get crypto prices

We then use the values above, passing them as parameters when calling the getTokenPrice() endpoint:

passing values as parameters when calling the getTokenPrice() endpoint to get crypto prices

That’s it; you’re now able to run your script! 

Step 3: Run the Code 

Lastly, all that continues to be from right here is operating the script. To take action, you simply have to open a brand new terminal and run the next command within the challenge’s root folder: 

node index.js

In return, you’ll get a response containing the token’s worth denominated in each USD and the blockchain’s native foreign money: 

{
  "tokenName": "Wrapped BTC",
  "tokenSymbol": "WBTC",
  "tokenLogo": "https://cdn.moralis.io/eth/0x2260fac5e5542a773aa44fbcfedf7c193bc2c599.png",
  "tokenDecimals": "8",
  "nativePrice": {
    "worth": "15844922382819160000",
    "decimals": 18,
    "identify": "Ether",
    "image": "ETH",
    "handle": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
  },
  "usdPrice": 29012.967874240312,
  "usdPriceFormatted": "29012.967874240312",
  "24hrPercentChange": "8.125434468247821",
  "exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
  "exchangeName": "Uniswap v3",
  "tokenAddress": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"
}

Congratulations! You now know tips on how to get the value of any token utilizing our Worth API! 

Additionally, you possibly can observe the very same steps if you wish to, as an example, get historic worth knowledge. All it requires are minor configurations to the code within the second a part of the tutorial.

What’s an API for Crypto Costs, and How Does it Work? 

A crypto API – brief for utility programming interface – is a set of protocols, guidelines, and strategies that can help you effortlessly work together with blockchain networks and combine Web3 performance into your initiatives. APIs primarily present structured methods to entry knowledge and carry out sure actions associated to cryptocurrencies and blockchain networks like Ethereum, Polygon, and BNB Good Chain. 

So, what’s an API for crypto costs? 

An API for crypto costs is a particular interface that makes a speciality of worth knowledge for cryptocurrencies. These sorts of interfaces can help you simply entry real-time and historic costs for numerous cryptocurrencies, together with ETH, MATIC, and every other tokens!

What is an API for Crypto Prices? Graphic Art Banner

In sum, an API for crypto costs makes the method of fetching worth knowledge from a blockchain community straightforward. With these interfaces, you should utilize premade protocols and strategies. This implies you don’t must reinvent the wheel to get the costs of cryptocurrencies. Moreover, this lets you save loads of improvement time and assets, highlighting the essential function that APIs for crypto costs play within the blockchain area! 

What to Consider When Selecting an API for Crypto Costs? 

Since there are numerous APIs for crypto costs, it may be difficult to search out one of the best match for you. As such, that will help you on this endeavor, we’ll cowl three issues to consider when selecting an API:

  • Protection: When selecting an API, token protection is among the most important issues. Subsequently, get your self an API for crypto costs masking a number of blockchain networks and a number of other DEXs. 
  • Options: Subsequent, you have to take into account options when selecting the correct API. Consequently, get an API that may fetch each real-time and historic crypto costs. What’s extra, search for extra advantages, resembling the power to arrange alerts. 
Graph showing components to incorporate when choosing an API for crypto prices
  • Worth: Lastly, you have to take into account the associated fee when selecting an API for crypto costs. The pricing is vital because it helps you narrow prices and keep aggressive within the quickly rising Web3 trade.

Now that you understand what to think about when choosing an API for crypto costs, let’s have a look at some distinguished use instances for these instruments!

API for Crypto Costs – Use Circumstances 

It doesn’t matter what Web3 challenge you’re seeking to construct, you’ll doubtless discover that you just want crypto worth knowledge. Which means that the use instances for crypto worth APIs are countless. Nevertheless, to present you some inspiration, we’ll take this part to cowl three distinguished examples: 

  • Portfolio Trackers: Portfolio trackers assist customers maintain observe of their funds throughout blockchain networks and crypto wallets. This offers them an summary of how their property carry out over time. Consequently, when constructing one, you want entry to each real-time and historic costs of cryptocurrencies.  
  • Web3 Wallets: Web3 wallets, additionally generally known as crypto wallets, are dapps enabling customers to retailer and handle their digital property, together with fungible and non-fungible tokens. Furthermore, Web3 wallets additionally give customers an summary of their holdings, together with the present worth of all tokens. As such, similar to when constructing a portfolio tracker, you want entry to cost knowledge. 
  • Token Explorers: Token explorers – like Moralis Cash – enable customers to search out new funding alternatives. They normally let customers filter their searches for cash primarily based on a number of components, one typically being worth change over time. Consequently, you want entry to historic and real-time costs of cryptocurrencies when constructing a token explorer. 
Token Explorer Example using a price api to get crypto price

Abstract: Moralis’ API for Crypto Costs – Quickest Solution to Get Costs of Crypto

At present’s article explored Moralis’ free crypto Worth API, which stands out because the trade’s greatest instrument for getting costs. Due to the accessibility of our Worth API, you possibly can seamlessly get the costs of any cryptocurrencies in three steps:  

  1. Get a Moralis API Key for Free
  2. Write a Script Calling the getTokenPrice() Endpoint
  3. Run the Code

Together with exhibiting you tips on how to get the real-time costs of any cryptocurrencies, we additionally confirmed you tips on how to get historic worth knowledge and make batch requests for a number of tokens concurrently. As such, you probably have adopted alongside this far, you now know tips on how to use one of the best API for getting crypto costs totally free. From right here, you’ll haven’t any hassle integrating worth knowledge into your initiatives. 

When you discovered this tutorial on one of the best API for getting crypto costs attention-grabbing, take into account trying out extra improvement content material right here on the Web3 weblog. For example, learn our Rinkeby faucet information, discover ways to test pockets exercise, or discover the idea of account abstraction! 

Additionally, if you wish to construct quicker and smarter, discover some extra instruments Moralis gives. For instance, try the NFT API and discover ways to get verified NFT collections or get all NFT tokens owned by a person handle, all with single strains of code! 

For entry to those instruments – together with one of the best API for getting crypto costs – join free with Moralis instantly! 



Source link

Tags: APIBitcoin NewsCryptoCrypto NewsCrypto UpdatesLatest News on CryptoPricesSB Crypto Guru News
Previous Post

Due diligence with crypto staking suppliers

Next Post

All Movies from Europe's Largest Bitcoin Convention Now Obtainable

Related Posts

Exploring Moonbeam – Why Build on Moonbeam? – Moralis Web3

Exploring Moonbeam – Why Build on Moonbeam? – Moralis Web3

by SB Crypto Guru News
September 11, 2024
0

In today’s tutorial, we’ll explore Moonbeam and the network’s benefits to explain why you might want to build on the...

Chiliz Chain Deep Dive – Why Build on Chiliz Chain? – Moralis Web3

Chiliz Chain Deep Dive – Why Build on Chiliz Chain? – Moralis Web3

by SB Crypto Guru News
September 10, 2024
0

In today’s article, we’ll explore the benefits of Chiliz to explain why you might want to build on this network....

NFT Rarity API – How to Get an NFT’s Rarity Ranking – Moralis Web3

NFT Rarity API – How to Get an NFT’s Rarity Ranking – Moralis Web3

by SB Crypto Guru News
September 6, 2024
0

Looking for the easiest way to get an NFT’s rarity ranking? If so, you’ve come to the right place. In...

How to Get Token Prices with an RPC Node – Moralis Web3

How to Get Token Prices with an RPC Node – Moralis Web3

by SB Crypto Guru News
September 3, 2024
0

Are you looking for an easy way to get token prices with an RPC node? If so, you’ve come to...

How to Get NFT Balances with One RPC Call – Moralis Web3

How to Get NFT Balances with One RPC Call – Moralis Web3

by SB Crypto Guru News
August 30, 2024
0

Did you know that with Moralis’ next-generation nodes, you can get NFT balances with just one RPC call? Our Extended...

Load More
Next Post
All Movies from Europe's Largest Bitcoin Convention Now Obtainable

All Movies from Europe's Largest Bitcoin Convention Now Obtainable

1 Solana (SOL) Value Goal on the Desk if Ethereum (ETH) Does This Subsequent Bull Cycle: InvestAnswers

$461 Solana (SOL) Value Goal on the Desk if Ethereum (ETH) Does This Subsequent Bull Cycle: InvestAnswers

Facebook Twitter LinkedIn Tumblr RSS

CATEGORIES

  • Altcoin
  • Analysis
  • Bitcoin
  • Blockchain
  • Crypto Exchanges
  • Crypto Updates
  • DeFi
  • Ethereum
  • Metaverse
  • Mining
  • NFT
  • Regulations
  • Scam Alert
  • Uncategorized
  • Web3

SITE MAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2022 - SB Crypto Guru News.
SB Crypto Guru News is not responsible for the content of external sites.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
  • HOME
  • BITCOIN
  • CRYPTO UPDATES
    • GENERAL
    • ALTCOINS
    • ETHEREUM
    • CRYPTO EXCHANGES
    • CRYPTO MINING
  • BLOCKCHAIN
  • NFT
  • DEFI
  • WEB3
  • METAVERSE
  • REGULATIONS
  • SCAM ALERT
  • ANALYSIS

Copyright © 2022 - SB Crypto Guru News.
SB Crypto Guru News is not responsible for the content of external sites.