Today’s article will dive into the ins and outs of the Moralis Web3 Market Data API. With this tool, you can seamlessly get the top ERC20 tokens by market cap, query the top trending NFT collections, and much more with only single lines of code. For a quick start, here are the four endpoints of the Web3 Market Data API:
getTopERC20TokensByMarketCap()
:
const response = await Moralis.EvmApi.marketData.getTopERC20TokensByMarketCap();
[ { "rank": 1, "token_name": "Wrapped Ether", "token_symbol": "WETH", "token_logo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png", "token_decimals": "18", "contract_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "price_usd": "1803.89", "price_24h_percent_change": "1.43", "price_7d_percent_change": "0.01", "market_cap_usd": "214188093967" }, //... ]
getTopERC20TokensByPriceMovers()
:
const response = await Moralis.EvmApi.marketData.getTopERC20TokensByPriceMovers();
{ "gainers": [ { "rank": "1", "token_name": "Wrapped Ether", "token_symbol": "WETH", "token_logo": "https://assets.coingecko.com/coins/images/2518/large/weth.png?1595348880", "token_decimals": "18", "contract_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "price_usd": "0.0285", "price_24h_percent_change": "0.0285", "price_7d_percent_change": "0.0285", "market_cap_usd": "0.0285" } ], //... }
getTopNFTCollectionsByMarketCap()
:
const response = await Moralis.EvmApi.marketData.getTopNFTCollectionsByMarketCap();
[ { "rank": "1", "collection_title": "CryptoPunks", "floor_price_usd": "0.0", "floor_price_24hr_percent_change": "0.0", "market_cap_usd": "0.0", "market_cap_24hr_percent_change": "0.0", "volume_usd": "0.0", "volume_24hr_percent_change": "0.0" } ]
getHottestNFTCollectionsByTradingVolume()
:
const response = await Moralis.EvmApi.marketData.getHottestNFTCollectionsByTradingVolume();
[ { "rank": 1, "collection_title": "Bored Ape Yacht Club", "collection_image": "https://market-data-images.s3.us-east-1.amazonaws.com/tokenImages/0x2f1ef58880d01489b8d2c9ba759cf7b14db4ee8a55fd6e6b222ad050e7e00fb0.png", "volume_usd": "8261189.224011", "volume_24hr_perecent_change": "17.09", "floor_price_usd": "79591.5288", "floor_price_24hr_percent_change": "0.05", "average_price_usd": "39717.255884668266" }, //... ]
To learn more about the Web3 Market Data API and the various endpoints, join us throughout this article, or check out the official Market Data API documentation!
By familiarizing yourself with the API for market data in Web3, you’ll be able to seamlessly integrate crypto market data into your future blockchain projects in no time. As such, don’t forget to sign up with Moralis, and you’ll be able to build faster and more efficiently!
Overview
We’ll kickstart today’s article by initially covering the ins and outs of crypto market data. In doing so, we will briefly explore what it is and why it’s important. From there, we’ll dive straight into the Moralis Web3 Market Data API, as this is the most accessible way to get crypto market data. We’ll then cover the endpoints of the API and show you how it works in practice with a quick three-step tutorial on how to get trending NFT collections. Lastly, to conclude the article, we’re going to explore five prominent Web3 Market Data API use cases!
Also, did you know that the API only scratches the surface of what’s possible with Moralis? If you’re serious about building Web3 projects, consider checking out some additional Moralis tools. For instance, explore the NFT API and learn how to get verified NFT collections in a heartbeat!
Nevertheless, without further ado, let’s continue with the article by looking at what market data in Web3 is!
What is a Web3 Market Data API? – Exploring Crypto Market Data
On-chain Web3 market data is an integral part of the crypto industry. Not only does it help traders make more informed investment decisions, but understanding and acquiring this type of Web3 data is also an essential part of blockchain development.
Web3 market data dictates everything from what NFT collections are becoming popular, what coins are about to shoot up to the top of the charts, or which tokens are currently losers. Consequently, it doesn’t matter if you’re building a Web3 wallet, NFT marketplace, or trading platform; you need an efficient way to integrate crypto market data into your projects to give your customers a compelling user experience (UX).
However, querying and deciphering this data is easier said than done. And if you were to do it yourself from scratch, it would require an abundance of development time and resources. Fortunately, you don’t have to reinvent the wheel when working with Moralis and the industry’s leading crypto Market Data API!
Introducing the #1 Web3 Market Data API
With the Moralis Web3 Market Data API, you can effortlessly unlock the full power of cryptocurrency market data. This tool lets you get trending NFT collections, top ERC20 tokens by market cap, and much more with only single lines of code. As such, when using Moralis, it has never been easier to build decentralized exchanges (DEXs), crypto wallets, portfolio trackers, or any other Web3 projects!
Using the Web3 Market Data API provides loads of benefits, and below, you can find three prominent examples:
- Engaged and Informed Users: Keep your users engaged and informed with trending Web3 market data.
- Improved User Experience (UX): Provide an improved UX with user-friendly features for your Web3 projects.
- Retain Customers: Keep your customers by providing up-to-date market data.
The Web3 Market Data API features the following four endpoints:
getTopERC20TokensByMarketCap()
getTopERC20TokensByPriceMovers()
getTopNFTCollectionsByMarketCap()
getHottestNFTCollectionsByTradingVolume()
In the sections to come, we’ll cover each one separately, giving you a more in-depth understanding of how they work!
Get Top ERC20 Tokens by Market Cap
With the getTopERC20TokensByMarketCap()
endpoint, you can effortlessly get the top ERC20 tokens by market cap with a single line of code:
const response = await Moralis.EvmApi.marketData.getTopERC20TokensByMarketCap();
In return for calling the endpoint above, you’ll get a response containing an array of the top ERC20 tokens by market cap. Here’s an example of what it might look like:
[ { "rank": 1, "token_name": "Wrapped Ether", "token_symbol": "WETH", "token_logo": "https://cdn.moralis.io/eth/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png", "token_decimals": "18", "contract_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "price_usd": "1803.89", "price_24h_percent_change": "1.43", "price_7d_percent_change": "0.01", "market_cap_usd": "214188093967" }, //... ]
Fetch Top ERC20 Tokens by Price Change
With the getTopERC20TokensByPriceMovers()
endpoint, you can seamlessly get the top ERC20 tokens by price change with a single call to the Web3 Market Data API:
const response = await Moralis.EvmApi.marketData.getTopERC20TokensByPriceMovers();
Calling the endpoint above provides a response containing the top gainer and loser by price change. This is an example of what the response can look like:
{ "gainers": [ { "rank": "1", "token_name": "Wrapped Ether", "token_symbol": "WETH", "token_logo": "https://assets.coingecko.com/coins/images/2518/large/weth.png?1595348880", "token_decimals": "18", "contract_address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "price_usd": "0.0285", "price_24h_percent_change": "0.0285", "price_7d_percent_change": "0.0285", "market_cap_usd": "0.0285" } ], //... }
Query Top NFT Collections by Market Cap
With the getTopNFTCollectionsByMarketCap()
endpoint, you can easily query the top NFT collections by market cap with only a single line of code:
const response = await Moralis.EvmApi.marketData.getTopNFTCollectionsByMarketCap();
In return for calling the getTopNFTCollectionsByMarketCap()
endpoint, you’ll receive a response with an array containing the top NFT collections by market cap. Here’s an example of what the response can look like:
[ { "rank": "1", "collection_title": "CryptoPunks", "floor_price_usd": "0.0", "floor_price_24hr_percent_change": "0.0", "market_cap_usd": "0.0", "market_cap_24hr_percent_change": "0.0", "volume_usd": "0.0", "volume_24hr_percent_change": "0.0" } ]
Get Trending NFT Collections by Trading Volume
With the getHottestNFTCollectionsByTradingVolume()
endpoint, you can effortlessly get trending NFT collections by trading volume with a simple call to the Web3 Market Data API:
const response = await Moralis.EvmApi.marketData.getHottestNFTCollectionsByTradingVolume();
Calling this endpoint will provide a response with an array containing the top trending NFT collections by trading volume. You’ll find an example of what the response might look like below:
[ { "rank": 1, "collection_title": "Bored Ape Yacht Club", "collection_image": "https://market-data-images.s3.us-east-1.amazonaws.com/tokenImages/0x2f1ef58880d01489b8d2c9ba759cf7b14db4ee8a55fd6e6b222ad050e7e00fb0.png", "volume_usd": "8261189.224011", "volume_24hr_perecent_change": "17.09", "floor_price_usd": "79591.5288", "floor_price_24hr_percent_change": "0.05", "average_price_usd": "39717.255884668266" }, //... ]
3-Step Tutorial: How to Get Web3 Market Data with the Moralis API
In the following sections, we’ll show you how to get Web3 market data with Moralis in three straightforward steps:
- Set Up Moralis
- Write a Script
- Execute the Code
To demonstrate the accessibility of the Web3 Market Data API, we’ll show you how to effortlessly get trending NFT collections by trading volume. However, you can follow precisely the same steps for any of the other endpoints to, for instance, get top ERC20 tokens by market cap, query top NFT collections by market cap, etc.
Nevertheless, before we can jump into the initial step of this crypto market data tutorial, you need to deal with a few prerequisites!
Prerequisites – Using the Web3 Market Data API
The Moralis API supports multiple programming languages, including JavaScript, Python, etc. However, for this tutorial, we’ll be using the former. Consequently, before you continue, make sure to have the following ready:
Step 1: Set Up Moralis
To call the Web3 Market Data API, you need a Moralis API key, and to get one, you need a Moralis account. As such, if you haven’t already, create your account immediately by clicking on the ”Start for Free” button at the top of Moralis’ homepage:
What’s more, in order to use the Web3 Market Data API, you also need at least Pro plan access. To get this, click on your profile at the bottom left, hit ”Account”, go to the ”Plan & Billing” tab, and upgrade to the Pro plan:
Once you’re a Pro plan user, you can click on the ”Settings” tab, scroll down to the ”Secrets” section, and copy your API key:
Keep the key for now, as you’ll need it in the next step.
Step 2: Write a Script
For the second step, set up a new project in your integrated development environment (IDE), open a new terminal, and run the following command in the root folder to install the Moralis SDK:
npm install moralis @moralisweb3/common-evm-utils
From there, you can then create a new ”index.js” file and add the following code:
const Moralis = require("moralis").default; const { EvmChain } = require("@moralisweb3/common-evm-utils"); const runApp = async () => { await Moralis.start({ apiKey: "YOUR_API_KEY", // ...and any other configuration }); const response = await Moralis.EvmApi.marketData.getHottestNFTCollectionsByTradingVolume(); console.log(response.raw); }; runApp();
Next, add your Moralis API key by replacing YOUR_API_KEY
:
We then simply call the getHottestNFTCollectionsByTradingVolume()
endpoint and log the response:
And that’s it for the code; you’re now ready to execute the script, and we’ll show you how in the next step!
Note: If you want to call any of the other crypto Market Data API endpoints, simply replace getHottestNFTCollectionsByTradingVolume()
in the script above.
Step 3: Execute the Code
To run the script, simply open a new terminal and run the following command in the project’s root folder:
node index.js
In return, you’ll get an array of the top trending NFT collections by trading volume. Here’s an example of what it might look like:
[ { "rank": 1, "collection_title": "Bored Ape Yacht Club", "collection_image": "https://market-data-images.s3.us-east-1.amazonaws.com/tokenImages/0x2f1ef58880d01489b8d2c9ba759cf7b14db4ee8a55fd6e6b222ad050e7e00fb0.png", "volume_usd": "8261189.224011", "volume_24hr_perecent_change": "17.09", "floor_price_usd": "79591.5288", "floor_price_24hr_percent_change": "0.05", "average_price_usd": "39717.255884668266" }, //... ]
Congratulations! That’s it; this is how easy it is to get the top trending NFT collections when working with Moralis and the Web3 Market Data API!
Web3 Market Data API Use Cases
The Web3 Market Data API is perfect for helping you build scalable decentralized applications (dapps). However, what exactly are the most prominent use cases for crypto market data? And how can you utilize this information when developing dapps?
To answer the questions above, join us in the preceding sections as we explore five prominent Web3 Market Data API use cases!
Decentralized Exchanges (DEXs)
A DEX is a peer-to-peer marketplace where users can exchange cryptocurrencies in a non-custodial manner without the need for intermediaries. Some prominent examples of successful DEXs include Uniswap, PancakeSwap, and Curve.
Access to real-time market data is a fundamental part of building and operating a DEX. This data is crucial in providing real-time pricing, giving users insight into the overall state of the market, and staying competitive in a rapidly growing market.
Web3 Wallets
Web3 wallets – also commonly referred to as crypto wallets – are platforms for storing assets like NFTs and fungible tokens. Some prominent actors within the space include MetaMask, Rainbow, and Phantom.
Using crypto market data when building a Web3 wallet can be highly beneficial, as this information can give your users valuable insight into their assets’ performance. What’s more, it can also, for instance, allow you to implement a neat token discovery feature, allowing users to find new investment opportunities by presenting the top ERC20 tokens based on price change.
NFT Marketplaces
NFT marketplaces are websites allowing you to buy and sell non-fungible tokens. Some prominent examples of successful platforms include OpenSea, Blur, and Rarible.
When building an NFT marketplace, it’s crucial that you have access to real-time Web3 on-chain data. For instance, giving your users insight into trending NFT collections can help them find new investment opportunities or value their current holdings.
Token Analytics
Token analytic platforms are tools traders can use to get valuable insight and data related to various cryptocurrencies. These platforms gather, process, and present data from blockchain networks, allowing users to make more informed investment decisions. A prominent example is Moralis Money!
As you can imagine, when building a token analytics platform, it’s essential that you have access to real-time Web3 market data. This will help users track the performance of digital assets so they can find the most promising tokens to invest in.
Portfolio Trackers
Portfolio tracker platforms are websites and software that allow users to track the performance of their assets across multiple blockchain networks. Some prominent examples include Moralis Money, Delta, and Kubera.
When building a portfolio tracker platform, you need access to real-time crypto market data as it gives you the opportunity to serve your customers with up-to-date asset valuations and performance metrics.
Summary: The Industry’s Leading Web3 Market Data API
In today’s article, we explored Moralis’ industry-leading Web3 Market Data API. And in doing so, we learned that it has four endpoints:
getTopERC20TokensByMarketCap()
getTopERC20TokensByPriceMovers()
getTopNFTCollectionsByMarketCap()
getHottestNFTCollectionsByTradingVolume()
In addition to exploring the endpoints, we also covered how you can call either one of them in three steps:
- Set Up Moralis
- Write a Script
- Execute the Code
As such, if you have followed along this far, you now know how to integrate crypto market data into your future Web3 projects using Moralis!
If you liked this tutorial, consider exploring additional articles on our Web3 blog. For instance, learn how to identify NFT and ERC20 spam and scam tokens, explore the concept of account abstraction, or read our Ethereum testnet guide. Also, if you’re serious about building blockchain projects, don’t forget to explore some additional Moralis APIs. For instance, check out the Token API and learn how to get the balance of ERC20 tokens from any account.
If you want access to these industry-leading tools like the Web3 Market Data API, remember to sign up with Moralis. You can create your account today and immediately start leveraging the true power of blockchain technology!
Read More: moralis.io