Saturday, May 17, 2025
No Result
View All Result
Coins League
  • Home
  • Bitcoin
  • Crypto Updates
    • Crypto Updates
    • Altcoin
    • Ethereum
    • Crypto Exchanges
  • Blockchain
  • NFT
  • DeFi
  • Metaverse
  • Web3
  • Scam Alert
  • Regulations
  • Analysis
Marketcap
  • Home
  • Bitcoin
  • Crypto Updates
    • Crypto Updates
    • Altcoin
    • Ethereum
    • Crypto Exchanges
  • Blockchain
  • NFT
  • DeFi
  • Metaverse
  • Web3
  • Scam Alert
  • Regulations
  • Analysis
No Result
View All Result
Coins League
No Result
View All Result

Free Crypto Price API – How to Get Live Cryptocurrency Prices

September 9, 2023
in Web3
Reading Time: 12 mins read
0 0
A A
0
Home Web3
Share on FacebookShare on TwitterShare on E Mail


In as we speak’s tutorial, we’ll present you find out how to use the {industry}’s #1 crypto worth API – the Moralis Value API – to fetch an asset’s real-time and historic worth. We’ll additionally briefly present you find out how to make batch requests to fetch the costs of a number of belongings concurrently. For those who’re wanting to get going, then listed here are three fast examples of the way it works: 

Fetch Actual-Time PricesWith a single API name to the getTokenPrice() endpoint, you may seamlessly fetch the real-time worth of an asset: import Moralis from ‘moralis’;

attempt {
await Moralis.begin({
apiKey: “YOUR_API_KEY”
});

const response = await Moralis.EvmApi.token.getTokenPrice({
“chain”: “0x1”,
“deal with”: “0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0”
});

console.log(response.uncooked);
} catch (e) {
console.error(e);
} Get Historic PricesBy specifying the toBlock parameter when calling the getTokenPrice() endpoint, you may effortlessly get the worth of an asset at a given time limit: import Moralis from ‘moralis’;

attempt {
await Moralis.begin({
apiKey: “YOUR_API_KEY”
});

const response = await Moralis.EvmApi.token.getTokenPrice({
“chain”: “0x1”,
“toBlock”: 18085987,
“deal with”: “0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0”
});

console.log(response.uncooked);
} catch (e) {
console.error(e);
} Make Batch RequestsYou could make batch requests by passing an array of addresses to get the worth of a number of tokens in a single response:// Dependencies to put in:
// $ npm set up node-fetch –save
// add “sort”: “module” to bundle.json

import fetch from ‘node-fetch’;

const choices = {
technique: ‘POST’,
headers: {
settle for: ‘utility/json’,
‘content-type’: ‘utility/json’,
‘X-API-Key’: ‘YOUR_API_KEY’
},
physique: JSON.stringify({
“tokens”: [
{
“token_address”: “0xae7ab96520de3a18e5e111b5eaab095312d7fe84”,
“to_block”: 16314545
}
]
})
};

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

Getting worth information with the Moralis Value API has by no means been simpler. By familiarizing your self with this API, you may spin up Web3 purposes very quickly. You too can study extra concerning the use instances above by testing the official Moralis Value API documentation. 

Additionally, don’t overlook to enroll with Moralis instantly so you can begin leveraging the total energy of the blockchain {industry} as we speak! 

Overview

We’ll kickstart as we speak’s article by exploring the intricacies of crypto worth APIs. From there, we’ll look nearer at why you would possibly want a worth API for cryptocurrency within the first place. Subsequent, we’re going to cowl some outstanding crypto worth API use instances. In doing so, we’ll introduce the Moralis Value API and present you find out how to use this software to fetch worth information. Extra particularly, we’ll present you find out how to: 

Fetch real-time worth dataGet historic token pricesMake batch requests

So, in case you are already aware of the ins and outs of crypto worth APIs, be happy to skip to the ”Crypto Value API Use Circumstances” part and get straight into the code! 

In any other case, be a part of us within the following part as we have a look at what a crypto worth API is!

What’s a Crypto Value API?

Cross-system communication is crucial when constructing purposes and web sites, as they don’t work optimally in isolation in as we speak’s interconnected world. As such, builders want environment friendly methods to allow decoupled software program techniques to speak with each other. Fortuitously, that is exactly the place APIs enter the equation. 

However what precisely is an API? And the way do they work within the context of Web3 improvement?

A crypto API, brief for utility programming interface, is a algorithm, protocols, and strategies permitting you to seamlessly work together with blockchain networks and combine crypto-related performance into your purposes, software program, and web sites. They supply a structured method to entry information and carry out actions associated to blockchain networks, cryptocurrencies, and decentralized purposes (dapps). 

A crypto worth API is a particular sort of interface specializing in worth information, and it permits you to seamlessly entry real-time and historic costs for numerous cryptocurrencies, like ETH (Ethereum), BTC (Bitcoin), and many others.

All in all, crypto worth APIs make the method of querying blockchain networks for pricing information easy. Moreover, they play an integral position within the Web3 improvement area, making your job as a developer considerably extra accessible! 

Why Do You Want a Stay Crypto Value API? 

It doesn’t matter in case you plan to construct a decentralized change (DEX) or the subsequent MetaMask; you’ll nearly at all times have to combine pricing information when constructing Web3 initiatives. And by leveraging a crypto worth API, it can save you an abundance of time and improvement assets! 

Querying blockchain networks is a tedious job, and in case you’re doing it from scratch, it could possibly shortly grow to be a time-consuming course of. So, as a substitute of “reinventing the wheel”, you may merely use a crypto worth API to get real-time and historic worth information with a couple of strains of code. That manner, you may allocate your time and assets towards extra vital duties like serving your finish customers. 

Illustrative image showing how live price data shows up when using a crypto price API

By leveraging a crypto worth API, you’ll immediately achieve a aggressive benefit and may transfer to market a lot faster than your rivals! 

Crypto Value API Use Circumstances

With an outline of what crypto worth APIs are and why you want them, let’s now discover the {industry}’s main interface: the Moralis Value API. The API supplied by Moralis has a number of use instances, and within the following sections, we’ll cowl three outstanding examples: 

Fetch real-time pricesGet historic worth dataMake batch requests

Moralis Price API - The Ultimate Crypto Price API - Get Started for Free!

Nevertheless, earlier than we present you find out how to use the Moralis Value API to fetch real-time token costs, you initially have to take care of a few stipulations! 

Stipulations 

Earlier than you get began with the free crypto Value API from Moralis, you initially have to have the next put in: 

Node v.14+ or PythonNPM/Yarn or Pip

You additionally have to register with Moralis to get your API key. As such, in case you haven’t already, hit the ”Begin for Free” button on the high proper on Moralis‘ homepage: 

Showing the Start For Free Button on Moralis Website

When you’ve arrange your account, go to the ”Web3 APIs” tab and hit the ”Get your API keys” button: 

Moralis UI and the Crypto Price API Key

With the API key at your disposal, you additionally have to run the next command within the root folder of your venture to put in the Moralis SDK: 

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

Now that’s it; you at the moment are prepared to start out utilizing the Moralis Value API to fetch worth information! So, with out additional ado, let’s leap straight into the primary use case and present you find out how to fetch real-time costs utilizing the {industry}’s main worth API for crypto! 

Fetch Actual-Time Costs 

With the Moralis Value API, you may effortlessly question the real-time worth of any ERC-20 token. All it requires is a single API name, and right here’s an instance of what it would appear to be: 

import Moralis from ‘moralis’;

attempt {
await Moralis.begin({
apiKey: “YOUR_API_KEY”
});

const response = await Moralis.EvmApi.token.getTokenPrice({
“chain”: “0x1”,
“deal with”: “0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0”
});

console.log(response.uncooked);
} catch (e) {
console.error(e);
}

When you run the code above, you’ll get a response wanting one thing like this: 

{
“tokenName”: “Matic Token”,
“tokenSymbol”: “MATIC”,
“tokenLogo”: “https://cdn.moralis.io/eth/0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0.png”,
“tokenDecimals”: “18”,
“nativePrice”: {
“worth”: “332947305392970”,
“decimals”: 18,
“identify”: “Ether”,
“image”: “ETH”,
“deal with”: “0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2”
},
“usdPrice”: 0.5423105104030737,
“usdPriceFormatted”: “0.5423105104030737”,
“exchangeAddress”: “0x1f98431c8ad98523631ae4a59f267346ea31f984”,
“exchangeName”: “Uniswap v3”,
“tokenAddress”: “0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0”
}

By merely passing the chain and contract deal with as parameters when calling the getTokenPrice() endpoint, you’ll get the token’s real-time worth denominated in each the native cryptocurrency of the chain and USD. 

Notice: Don’t overlook to interchange YOUR_API_KEY along with your precise Moralis API key.  

Get Historic Value Information 

Along with fetching the real-time worth of a token, you may simply as simply use the Moralis Value API to question the worth at any given time limit. To take action, you merely have to enter a timestamp or a block quantity, and the crypto Value API from Moralis takes care of the remainder! 

So, how does it work? 

To get the historic worth of a token, you may merely use the getTokenPrice() endpoint as soon as once more. Nevertheless, this time, you could specify the toBlock parameter. Right here’s an instance of what it could possibly appear to be:

import Moralis from ‘moralis’;

attempt {
await Moralis.begin({
apiKey: “YOUR_API_KEY”
});

const response = await Moralis.EvmApi.token.getTokenPrice({
“chain”: “0x1”,
“toBlock”: 18085987,
“deal with”: “0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0”
});

console.log(response.uncooked);
} catch (e) {
console.error(e);
}

In return, you’ll get a response wanting one thing like this: 

{
“tokenName”: “Matic Token”,
“tokenSymbol”: “MATIC”,
“tokenLogo”: “https://cdn.moralis.io/eth/0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0.png”,
“tokenDecimals”: “18”,
“nativePrice”: {
“worth”: “338661989977717”,
“decimals”: 18,
“identify”: “Ether”,
“image”: “ETH”,
“deal with”: “0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2”
},
“usdPrice”: 0.5535986848542233,
“usdPriceFormatted”: “0.5535986848542233”,
“exchangeAddress”: “0x1f98431c8ad98523631ae4a59f267346ea31f984”,
“exchangeName”: “Uniswap v3”,
“tokenAddress”: “0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0”,
“toBlock”: “18085987”
}

As soon as once more, you get the worth denominated in each the chain’s native token in addition to USD. Nevertheless, this time, it’s the worth from the desired timestamp/block quantity.

Notice: Don’t overlook to interchange YOUR_API_KEY along with your precise Moralis API key.  

Make Batch Requests 

Lastly, with the Moralis Value API, you can also make batch requests to fetch the worth of a number of tokens concurrently and in a single response. To take action, you merely have to specify an array of token addresses, and right here’s an instance of what it would appear to be: 

// Dependencies to put in:
// $ npm set up node-fetch –save
// add “sort”: “module” to bundle.json

import fetch from ‘node-fetch’;

const choices = {
technique: ‘POST’,
headers: {
settle for: ‘utility/json’,
‘content-type’: ‘utility/json’,
‘X-API-Key’: ‘YOUR_API_KEY’
},
physique: JSON.stringify({
“tokens”: [
{
“token_address”: “0xae7ab96520de3a18e5e111b5eaab095312d7fe84”,
“to_block”: 16314545
}
]
})
};

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

In return, you’ll obtain an array containing token costs denominated within the blockchain’s native foreign money and USD. Right here’s an instance response:

[
{
“tokenName”: “stETH”,
“tokenSymbol”: “stETH”,
“tokenLogo”: “https://cdn.moralis.io/eth/0xae7ab96520de3a18e5e111b5eaab095312d7fe84.png”,
“tokenDecimals”: “18”,
“nativePrice”: {
“value”: “985900938416575600”,
“decimals”: 18,
“name”: “Ether”,
“symbol”: “ETH”,
“address”: “0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2”
},
“usdPrice”: 1183.2332106724853,
“usdPriceFormatted”: “1183.2332106724853”,
“24hrPercentChange”: “-27.08746487985908”,
“exchangeAddress”: “0x1f98431c8ad98523631ae4a59f267346ea31f984”,
“exchangeName”: “Uniswap v3”,
“tokenAddress”: “0xae7ab96520de3a18e5e111b5eaab095312d7fe84”,
“toBlock”: “16314545”
}
]

That’s it; when working with the Moralis Value API, it doesn’t need to be extra complicated than that to fetch present and historic token costs! 

Notice: Don’t overlook to interchange YOUR_API_KEY along with your precise Moralis API key.  

Why Use the Moralis Crypto Value API? 

Together with the use instances above, there are a number of extra the explanation why you need to go for the Moralis Value API for crypto. To spotlight why, we’ll have a look at some advantages and benefits of Moralis’ industry-leading crypto Value API on this part! 

Illurtation of various token prices being fed using the Moralis Crypto Price API

Costs for All Tokens: You probably have had sufficient of awful protection and lacking tokens, you then’ll wish to begin utilizing the Moralis Value API. With this API, cash present up instantaneously as they begin buying and selling on any DEX. We monitor each new coin and liquidity pool to provide the newest worth information as quickly because it turns into accessible. There are not any approval processes and no gatekeeping! Assist for All Main EVM Chains: The Moralis Value API helps all main EVM chains and a number of DEXs. Some outstanding examples embrace QuickSwap, Camelot, Uniswap, TraderJoe, and lots of others. Consequently, the Moralis Value API is the one worth API you could construct your Web3 initiatives!

Now, how does Moralis evaluate to different crypto worth API suppliers? 

The Moralis Crypto Value API vs. Different Options 

With protection starting from the smallest and latest cash to essentially the most well-established cryptocurrencies, Moralis gives essentially the most complete API in the marketplace. Moreover, the Moralis crypto Value API is the {industry}’s premier possibility by any metric, together with options, aggressive pricing, and velocity! 

As an illustration, right here’s a comparability with rivals like CoinMarketCap and CoinGecko:

Moralis Crypto Price API vs CoinGecko Price API vs CoinMarketCap Crypto API - Table with Metrics

So, in case you’re planning to construct a Web3 venture the place you want worth information, create your free Moralis account as we speak and begin leveraging the true energy of blockchain know-how!

Past the Crypto Value API 

The Value API for crypto is simply the tip of the iceberg, and there’s much more to Moralis. Moreover, the free crypto Value API works like a appeal along with the opposite interfaces in Moralis’ Web3 API suite. As such, in case you’re severe about constructing Web3 initiatives, take into account checkout out a few of our different merchandise: 

Pockets API: The proper API for constructing Web3 wallets.Token API: A strong out-of-the-box resolution for fetching ERC-20 token information in actual time.Stability API: Get the token steadiness for any person pockets.DeFi API: Fetch pair and liquidity reserve information throughout a number of blockchain networks. Transaction API: Get detailed transactions and log information in a heartbeat. 

Moralis’ Multi-Chain Compatibility 

Do you know you don’t restrict your self to 1 blockchain community when working with Moralis? Moralis helps chain-agnostic constructing, which means you may construct Web3 initiatives and dapps throughout the preferred blockchain networks. Some outstanding examples embrace Ethereum, BNB Sensible Chain, Polygon, Avalanche, and lots of others.

The Moralis group is working onerous each day on including new networks and integrations. As such, you may count on extra blockchain networks and much more cross-chain compatibility sooner or later!

Abstract: Free Crypto Value API 

We kickstarted as we speak’s article by exploring the ins and outs of worth APIs for crypto. In doing so, we realized {that a} crypto worth API is a algorithm, strategies, and protocols enabling you to effortlessly work together with and combine blockchain-related performance into your initiatives. 

From there, we launched the Moralis Value API for crypto. Moreover, we demonstrated find out how to fetch real-time token costs, get historic token costs, and make batch requests! Consequently, in case you have adopted alongside this far, you now know find out how to use the Moralis Value API to fetch the information you could construct extra subtle Web3 initiatives! 

If that is your ambition, be happy to take a look at some extra content material right here on the Web3 weblog. As an illustration, discover ways to create a blockchain explorer or dive into Web3 market improvement. 

Additionally, in case you haven’t already, be sure to enroll with Moralis. You possibly can create your account free of charge to get speedy entry to the varied APIs. With these instruments, you can begin leveraging the total energy of Web3 know-how right away!



Source link

Tags: APIcryptoCryptocurrencyFreelivePricePrices
Previous Post

XRP Price Prediction – Breaking This Confluence Resistance Could Spark Recovery

Next Post

How To Lose Your Crypto, Using ChatGPT.

Related Posts

Judge Rejects SEC and Ripple’s Bid to Rework XRP Settlement
Web3

Judge Rejects SEC and Ripple’s Bid to Rework XRP Settlement

May 16, 2025
What’s Up Grok? AI Under Fire for Injecting ‘White Genocide’ Claims Into Unrelated Replies
Web3

What’s Up Grok? AI Under Fire for Injecting ‘White Genocide’ Claims Into Unrelated Replies

May 15, 2025
UNDER EXPOSED EP 25 – Decrypt
Web3

UNDER EXPOSED EP 25 – Decrypt

May 13, 2025
BitGo Gains EU-Wide Approval to Serve Institutions Under New Crypto Rules
Web3

BitGo Gains EU-Wide Approval to Serve Institutions Under New Crypto Rules

May 12, 2025
Yat Siu on building web3’s most influential unicorn 
Web3

Yat Siu on building web3’s most influential unicorn 

May 12, 2025
The Vibes From Dubai: What Token2049 Chatter Reveals About the Future of Crypto
Web3

The Vibes From Dubai: What Token2049 Chatter Reveals About the Future of Crypto

May 11, 2025
Next Post
How To Lose Your Crypto, Using ChatGPT.

How To Lose Your Crypto, Using ChatGPT.

Digital Resonance Panel Sheds Light on Diversity, Innovation, and the Future

Digital Resonance Panel Sheds Light on Diversity, Innovation, and the Future

Crypto whale loses over $24M staked Ethereum to phishing, as ‘verified’ X scams surge

Crypto whale loses over $24M staked Ethereum to phishing, as ‘verified’ X scams surge

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Twitter Instagram LinkedIn RSS Telegram
Coins League

Find the latest Bitcoin, Ethereum, blockchain, crypto, Business, Fintech News, interviews, and price analysis at Coins League

CATEGORIES

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

SITEMAP

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

Copyright © 2023 Coins League.
Coins League is not responsible for the content of external sites.

No Result
View All Result
  • Home
  • Bitcoin
  • Crypto Updates
    • Crypto Updates
    • Altcoin
    • Ethereum
    • Crypto Exchanges
  • Blockchain
  • NFT
  • DeFi
  • Metaverse
  • Web3
  • Scam Alert
  • Regulations
  • Analysis

Copyright © 2023 Coins League.
Coins League 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