Comprehensive Blockchain API Guide
In this blockchain API tutorial, we'll explore various API examples to retrieve vital blockchain data. We'll focus on Mobula's cutting-edge Blockchain API, renowned for its versatility in market data, wallet data, pair data, data history, metadata and more. For a preview, here's an example of using Mobula's Blockchain API to retrieve Bitcoin price with a single call:
const options = {method: 'GET'};
fetch('https://api.mobula.io/api/1/market/data?asset=Bitcoin', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
Simply add the asset parameter to match your query before calling the endpoint in the provided example. Upon execution, you'll receive a response containing details such as the market cap, liquidity, volume, price, price change, and more. Here's an example of the expected response format:
{
"data": {
"market_cap": 1261445854396,
"market_cap_diluted": 1350307466879,
"liquidity": 253224533,
"price": 64300.355565680395,
"off_chain_volume": 43354148526,
"volume": 322984032,
"volume_change_24h": -52.327674865722656,
"volume_7d": 345759936,
"is_listed": true,
"price_change_24h": -4.209524,
"price_change_1h": 0.0666601,
"price_change_7d": 1.4587651,
"price_change_1m": 25.990932,
"price_change_1y": 126.04035,
"ath": 73426.18983181914,
"atl": 67.809,
"name": "Bitcoin",
"symbol": "BTC",
"logo": "https://metacore.mobula.io/ea67a92c8e0a9b951d6fafed56e8ee714180e9ccbadb7d0555b9cb1b1224dba7.png",
"rank": 1,
"contracts": [
{
"address": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
"blockchain": "Ethereum",
"blockchainId": "1",
"decimals": 8
},
{
"address": "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c",
"blockchain": "BNB Smart Chain (BEP20)",
"blockchainId": "56",
"decimals": 18
},
{
"address": "0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6",
"blockchain": "Polygon",
"blockchainId": "137",
"decimals": 8
},
{
"address": "0x50b7545627a5162f82a992c33b87adc75187b218",
"blockchain": "Avalanche C-Chain",
"blockchainId": "43114",
"decimals": 8
},
{
"address": "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f",
"blockchain": "Arbitrum",
"blockchainId": "42161",
"decimals": 8
},
{
"address": "0x6ab6d61428fde76768d7b45d8bfeec19c6ef91a8",
"blockchain": "Moonriver",
"blockchainId": "1285",
"decimals": 8
},
{
"address": "0xd629eb00deced2a080b7ec630ef6ac117e614f1b",
"blockchain": "Celo",
"blockchainId": "42220",
"decimals": 18
},
{
"address": "0xdc0486f8bf31df57a952bcd3c1d3e166e3d9ec8b",
"blockchain": "Boba",
"blockchainId": "288",
"decimals": 8
},
{
"address": "0x062e66477faf219f25d27dced647bf57c3107d52",
"blockchain": "Cronos",
"blockchainId": "25",
"decimals": 8
},
{
"address": "0xf4eb217ba2454613b15dbdea6e5f22276410e89e",
"blockchain": "Aurora",
"blockchainId": "1313161554",
"decimals": 8
},
{
"address": "0x68f180fcce6836688e9084f035309e29bf0a2095",
"blockchain": "Optimistic",
"blockchainId": "10",
"decimals": 8
},
{
"address": "0x8e5bbbb09ed1ebde8674cda39a0c169401db4252",
"blockchain": "XDAI",
"blockchainId": "100",
"decimals": 8
},
{
"address": "0x922d641a426dcffaef11680e5358f34d97d112e1",
"blockchain": "Moonbeam",
"blockchainId": "1284",
"decimals": 8
},
{
"address": "xUTp3RXGJ1fJpCGqsAY6GgyfRQ3WQ1MdcYR1SiwndAbR",
"blockchain": "Alephium",
"blockchainId": "alephium-0",
"decimals": 8
}
]
}
}
That's all there is to it, accessing blockchain data with Mobula doesn't have to be complicated. However, if you're interested in a more in-depth tutorial and exploring additional endpoints, keep reading! Also, if you'd like to follow along and make similar calls yourself, be sure to register with Mobula. Signing up is free, and it immediately grants you access to the full potential of blockchain data!
Overview
Today's tutorial initiates with a comprehensive review of the Mobula Blockchain API, focusing on its features and primary advantages. It then transitions to a detailed walkthrough on utilizing the API for one of its most compelling applications: fetching cryptocurrency prices. The guide is structured to demonstrate this functionality through a concise three-step process:
- Obtain a Mobula API key
- Develop a script to Use the market/data endpoint
- Execute the script
For enthusiasts committed to blockchain development, we also recommend delving into Mobula's suite of Web3 data tools, including but not limited to the Price API, for seamless cryptocurrency price integration into your projects.
Let's get started with the essentials of the Mobula Blockchain API.
What is the Mobula Blockchain API?
The Mobula Blockchain API stands as a forefront solution for accessing detailed blockchain data swiftly and accurately. It allows the retrieval of essential blockchain elements such as market data, wallet data, pair data, and metadata through just a few lines of code. This makes the process of crafting Web3 projects notably more straightforward with Mobula.
The Blockchain API offers a comprehensive suite of functionalities tailored for enhanced blockchain data analysis and interaction:
- Market Data: Access current data on market conditions, including asset prices, liquidity levels, and market cap across various assets and platforms.
- Pair Data: Obtain specifics on trading pairs, including volume, price changes, and available liquidity, facilitating a deeper understanding of market dynamics.
- Wallet Data: Explore detailed information related to individual wallets, covering balances, asset holdings, and transaction activities, offering a granular view of wallet operations.
- Market History: Delve into historical market data, capturing trends, price movements, and liquidity changes over time, crucial for trend analysis and forecasting.
- Wallet History: Track the transaction history of wallets, including incoming and outgoing transactions, to gain insights into wallet behavior over time.
- Metadata: Access enriched data providing context and additional information about transactions, assets, and wallets, enhancing data interpretation and decision-making processes.
These features, crafted for broad utility, support a range of applications from market analysis to individual wallet monitoring, backed by the API's ability to interface with major blockchain networks for comprehensive coverage.
Benefits of the Mobula Blockchain API
The Mobula Blockchain API doesn't just come with an array of advanced features; it also offers significant benefits that enhance project development. Here are four key advantages:
- Scalability: Designed to support growth, the Mobula Blockchain API effortlessly scales to match your project's expanding needs and user base without compromising on performance.
- Real-Time Data: It provides swift access to the latest blockchain information by indexing data in real-time, ensuring your projects are always up to date.
- Accuracy: Recognizing the critical need for reliable data in Web3 projects, the Mobula Blockchain API commits to delivering precise and trustworthy information.
- Organization: Understanding the complexity of blockchain data, the API presents an organized structure, categorizing blocks into transfers, transactions, and logs for easy navigation and analysis.
With these benefits, the Mobula Blockchain API stands out as a premier choice for developers venturing into the Web3 space. Let's delve into its practical applications!
Blockchain API Examples and Use Cases
The Mobula Blockchain API serves a variety of critical use cases in the blockchain space. Here, we will highlight three instances:
Algorithmic Trading Platforms: Algorithmic trading platforms use automated, pre-programmed trading instructions to execute orders at high speeds and volumes, which can be based on a variety of conditions including time, price, and volume. These platforms demand real-time, precise market data to make informed decisions and capitalize on market movements.
- For algorithmic trading to be effective, access to up-to-the-second market data—such as asset prices, trading volumes, and liquidity metrics—is crucial. This data enables algorithms to perform technical analysis, identify trading opportunities, and execute trades with optimal timing. Utilizing the Mobula Blockchain API provides these platforms with the detailed and timely market data they require, facilitating efficient and informed trading strategies.
Wallet Data Platforms: Wallet data platforms function as digital vaults that facilitate the storage and management of digital assets, encompassing both fungible and non-fungible tokens. Notable examples in the market include MetaMask and Rainbow.
- A key functionality of these platforms is showcasing the user's wallet activity, offering a comprehensive view of their transactions and trades. This feature is invaluable for users seeking insights into their digital asset movements. To accurately display such detailed transaction information and events, the integration of a robust Blockchain API, like the Mobula Blockchain API, is essential, providing the necessary data for a complete activity overview.
Decentralized Exchange (DEX) Analytics Platforms: DEX analytics platforms provide insights into trading activities on decentralized exchanges, offering data on trading pairs, liquidity pools, and price movements. These platforms are crucial for traders and investors looking to understand market trends, identify high-potential trading pairs, and track liquidity shifts across various decentralized exchanges.
- To deliver this in-depth analysis, these platforms must have access to real-time and historical data on trading pairs, including volume, price fluctuations, and liquidity changes. The Mobula Blockchain API can supply this critical pair data, enabling DEX analytics platforms to offer comprehensive insights and analytics. By leveraging the API, these platforms can enhance their ability to provide users with actionable intelligence on the decentralized trading landscape.
Algorithmic Trading Platforms: JavaScript Blockchain API Example
When developing an algorithmic trading platform, real-time access to detailed market data is paramount. The Mobula Blockchain API facilitates this by offering an efficient way to fetch current market conditions, including asset prices and trading volumes.
For algorithmic trading platforms seeking up-to-the-minute market data, integrating with the Mobula Blockchain API is straightforward. Here’s an example of how to fetch current market data for an asset like Bitcoin:
const options = {method: 'GET'};
fetch('https://api.mobula.io/api/1/market/data?asset=Bitcoin', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
This code snippet demonstrates how to call the Mobula Blockchain API to retrieve market data for Bitcoin, providing algorithmic trading platforms with essential information for executing trades based on the latest market conditions.
When you utilize the endpoint as illustrated, you'll receive an extensive response packed with valuable data.
{
"data": {
"market_cap": 1236067404033,
"market_cap_diluted": 1320746567037,
"liquidity": 227710446,
"price": 62892.69366842296,
"off_chain_volume": 44265674371,
"volume": 366026016,
"volume_change_24h": -43.313724517822266,
"volume_7d": 366026016,
"is_listed": true,
"price_change_24h": -6.1723824,
"price_change_1h": -1.1129564,
"price_change_7d": 1.4587651,
"price_change_1m": 23.166086,
"price_change_1y": 120.97229,
"ath": 73426.18983181914,
"atl": 67.809,
"name": "Bitcoin",
"symbol": "BTC",
"logo": "https://metacore.mobula.io/ea67a92c8e0a9b951d6fafed56e8ee714180e9ccbadb7d0555b9cb1b1224dba7.png",
"rank": 1,
"contracts": [
{
"address": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
"blockchain": "Ethereum",
"blockchainId": "1",
"decimals": 8
},
{
"address": "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c",
"blockchain": "BNB Smart Chain (BEP20)",
"blockchainId": "56",
"decimals": 18
},
{
"address": "0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6",
"blockchain": "Polygon",
"blockchainId": "137",
"decimals": 8
},
{
"address": "0x50b7545627a5162f82a992c33b87adc75187b218",
"blockchain": "Avalanche C-Chain",
"blockchainId": "43114",
"decimals": 8
},
{
"address": "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f",
"blockchain": "Arbitrum",
"blockchainId": "42161",
"decimals": 8
},
{
"address": "0x6ab6d61428fde76768d7b45d8bfeec19c6ef91a8",
"blockchain": "Moonriver",
"blockchainId": "1285",
"decimals": 8
},
{
"address": "0xd629eb00deced2a080b7ec630ef6ac117e614f1b",
"blockchain": "Celo",
"blockchainId": "42220",
"decimals": 18
},
{
"address": "0xdc0486f8bf31df57a952bcd3c1d3e166e3d9ec8b",
"blockchain": "Boba",
"blockchainId": "288",
"decimals": 8
},
{
"address": "0x062e66477faf219f25d27dced647bf57c3107d52",
"blockchain": "Cronos",
"blockchainId": "25",
"decimals": 8
},
{
"address": "0xf4eb217ba2454613b15dbdea6e5f22276410e89e",
"blockchain": "Aurora",
"blockchainId": "1313161554",
"decimals": 8
},
{
"address": "0x68f180fcce6836688e9084f035309e29bf0a2095",
"blockchain": "Optimistic",
"blockchainId": "10",
"decimals": 8
},
{
"address": "0x8e5bbbb09ed1ebde8674cda39a0c169401db4252",
"blockchain": "XDAI",
"blockchainId": "100",
"decimals": 8
},
{
"address": "0x922d641a426dcffaef11680e5358f34d97d112e1",
"blockchain": "Moonbeam",
"blockchainId": "1284",
"decimals": 8
},
{
"address": "xUTp3RXGJ1fJpCGqsAY6GgyfRQ3WQ1MdcYR1SiwndAbR",
"blockchain": "Alephium",
"blockchainId": "alephium-0",
"decimals": 8
}
]
}
}
Note: Although the example provided utilizes Javascript, the Mobula Blockchain API is compatible with various programming languages, including Python, TypeScript, and more. For detailed instructions on implementing this functionality in other languages and to explore comprehensive documentation on fetching transactions for a specific address, be sure to visit the official documentation page on getting transactions of an address.
Wallet Data Platforms: Python Blockchain API Example
For Wallet Data Platforms focusing on providing users with their comprehensive wallet portfolio, utilizing the Mobula Blockchain API becomes essential. By leveraging the wallet/transactions
endpoint, you can extract a detailed transaction history and portfolio composition with just the wallet address as a mandatory parameter. Here’s an updated Python example reflecting these requirements:
import requests
url = "https://api.mobula.io/api/1/wallet/transactions"
querystring = {"wallet":"0xYourWalletAddress"}
response = requests.request("GET", url, params=querystring)
print(response.text)
This snippet is crafted to help Wallet Data Platforms query the Mobula Blockchain API efficiently, requiring only a wallet address to fetch a user's portfolio data, streamlining the process of displaying comprehensive wallet activities and holdings.
When you call the wallet/transactions
endpoint, the response will include an array detailing all inbound and outbound transactions associated with the specified address. The response format typically provides comprehensive transaction data, including transaction hashes, amounts, dates, and other relevant details. Here's an example of what such a response might look like:
{
"data": {
"wallet": "0x2dad5d1255983775f505c9a1ebe132098b4b8375",
"transactions": [
{
"timestamp": 1675855370000,
"asset": {
"name": "Ethereum",
"symbol": "ETH",
"contract": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",
"logo": "https://metacore.mobula.io/60989b438a473ed77703f7bcd3530fc15542996a6607ae831de8c5e3e10f688d.png",
"id": 100004304
},
"type": "buy",
"method_id": null,
"hash": "0x1ed408f933b19885a9a23b5097b7c24a6a73a6d7cf72caf4a9a2b8e8cf775d21",
"blockchain": "BNB Smart Chain (BEP20)",
"amount": 0.005,
"amount_usd": 8.364,
"to": "0x2dad5d1255983775f505c9a1ebe132098b4b8375",
"from": "0x5804fa818c844ec35c9139ed0c58430d8f17e3f3"
},
{
"timestamp": 1675856423000,
"asset": {
"name": "Ethereum",
"symbol": "ETH",
"contract": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"logo": "https://metacore.mobula.io/60989b438a473ed77703f7bcd3530fc15542996a6607ae831de8c5e3e10f688d.png",
"id": 100004304
},
"type": "buy",
"method_id": "0x",
"hash": "0x1da24b4c000f7c99a33c38ff32c98f9e7fa533695411e8f4f19de85cdc50f51c",
"blockchain": "Ethereum",
"amount": 0.0088,
"amount_usd": 14.721,
"to": "0x2dad5d1255983775f505c9a1ebe132098b4b8375",
"from": "0x28c6c06298d514db089934071355e5743bf21d60"
},
{
"timestamp": 1675872167000,
"asset": {
"name": "Ethereum",
"symbol": "ETH",
"contract": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"logo": "https://metacore.mobula.io/60989b438a473ed77703f7bcd3530fc15542996a6607ae831de8c5e3e10f688d.png",
"id": 100004304
},
"type": "buy",
"method_id": "0xded9382a",
"hash": "0xe20a7f207d6392962f9d2277e9100996d26c85ebbbd1dc52a7426320acb04c9c",
"blockchain": "Ethereum",
"amount": 1.4411976283544257,
"amount_usd": 2380.006,
"to": "0x2dad5d1255983775f505c9a1ebe132098b4b8375",
"from": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d",
"tx_cost": 0.01385550083997444
},
{
"timestamp": 1676035583000,
"asset": {
"name": "Based AI",
"symbol": "BASED",
"contract": "0xfeae0b386a2e6842cc61c152b9ef9402badac04b",
"logo": "https://metacore.mobula.io/e2d329f6717aa3eebd3fe01de27f6903284509cceba66300a4d4b9c4804db1ac.png",
"id": 486
},
"type": "buy",
"method_id": null,
"hash": "0x5e6e146768ce0ccdfc9829a25dc62307b424261a904bfe060d193670d3c42b64",
"blockchain": "Ethereum",
"amount": 36149.15680310213,
"amount_usd": 0,
"to": "0x2dad5d1255983775f505c9a1ebe132098b4b8375",
"from": "0x0000000000000000000000000000000000000000"
},
{
"timestamp": 1676035691000,
"asset": {
"name": "Ethereum",
"symbol": "ETH",
"contract": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"logo": "https://metacore.mobula.io/60989b438a473ed77703f7bcd3530fc15542996a6607ae831de8c5e3e10f688d.png",
"id": 100004304
},
"type": "sell",
"method_id": "0x095ea7b3",
"hash": "0xebb2ecf63fc933ad91818abe7c77f5763237733dcd21f7073d2774ecb7494b34",
"blockchain": "Ethereum",
"amount": 0,
"amount_usd": 0,
"to": "0xfeae0b386a2e6842cc61c152b9ef9402badac04b",
"from": "0x2dad5d1255983775f505c9a1ebe132098b4b8375",
"tx_cost": 0.00069973547927962
},
{
"timestamp": 1676035691000,
"asset": {
"name": "Ethereum",
"symbol": "ETH",
"contract": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"logo": "https://metacore.mobula.io/60989b438a473ed77703f7bcd3530fc15542996a6607ae831de8c5e3e10f688d.png",
"id": 100004304
},
"type": "sell",
"method_id": "0x095ea7b3",
"hash": "0xcec32d43bd8158a20a198c546252b64fa32ae5d8b872d311031800782db96138",
"blockchain": "Ethereum",
"amount": 0,
"amount_usd": 0,
"to": "0xfeae0b386a2e6842cc61c152b9ef9402badac04b",
"from": "0x2dad5d1255983775f505c9a1ebe132098b4b8375",
"tx_cost": 0.00122547496571262
},
{
"timestamp": 1676036399000,
"asset": {
"name": "Based AI",
"symbol": "BASED",
"contract": "0xfeae0b386a2e6842cc61c152b9ef9402badac04b",
"logo": "https://metacore.mobula.io/e2d329f6717aa3eebd3fe01de27f6903284509cceba66300a4d4b9c4804db1ac.png",
"id": 486
},
"type": "sell",
"method_id": null,
"hash": "0x552a3caf6a797fe92e42ca609f768fb37fb18125af99b2c0a2483cad8e2eeabd",
"blockchain": "Ethereum",
"amount": 36149.15680310213,
"amount_usd": 0,
"to": "0xe2fe530c047f2d85298b07d9333c05737f1435fb",
"from": "0x2dad5d1255983775f505c9a1ebe132098b4b8375"
},
{
"timestamp": 1689873959000,
"asset": {
"name": "Ethereum",
"symbol": "ETH",
"contract": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"logo": "https://metacore.mobula.io/60989b438a473ed77703f7bcd3530fc15542996a6607ae831de8c5e3e10f688d.png",
"id": 100004304
},
"type": "sell",
"method_id": "0x4c5f7f54",
"hash": "0x2ba82deab712ee133eb3ebfcf2b0b91eb5a22a5d719937226754ea1f4a2fa1ff",
"blockchain": "Ethereum",
"amount": 0,
"amount_usd": 0,
"to": "0xe2fe530c047f2d85298b07d9333c05737f1435fb",
"from": "0x2dad5d1255983775f505c9a1ebe132098b4b8375",
"tx_cost": 0.004207459871312685
}
],
"total": 21,
"offset": 0,
"limit": 100,
"page": 1,
"lastUpdated": {
"Base": {
"normal": 0,
"internal": 0,
"token": 0,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119287034
},
"Blast": {
"normal": 0,
"internal": 0,
"token": 0,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119287066
},
"Linea": {
"normal": 0,
"internal": 0,
"token": 0,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119287018
},
"Cronos": {
"normal": 0,
"internal": 0,
"token": 0,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119287138
},
"Fantom": {
"normal": 0,
"internal": 0,
"token": 0,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119286961
},
"Mantle": {
"normal": 0,
"internal": 0,
"token": 0,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119287357
},
"Polygon": {
"normal": 0,
"internal": 0,
"token": 0,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119287750
},
"Arbitrum": {
"normal": 0,
"internal": 0,
"token": 0,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119286997
},
"Ethereum": {
"normal": 17735852,
"internal": 16598714,
"token": 16598714,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119287593
},
"Optimistic": {
"normal": 0,
"internal": 0,
"token": 0,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119287067
},
"Avalanche C-Chain": {
"normal": 0,
"internal": 0,
"token": 0,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119287353
},
"BNB Smart Chain (BEP20)": {
"normal": 0,
"internal": 0,
"token": 25487602,
"deposit": 0,
"type": "EVM",
"lastUpdated": 1711119287648
}
}
},
"details": null
}
Note: Although the example provided utilizes Python, the Mobula Blockchain API is compatible with various programming languages, including JavaScript, TypeScript, and more. For detailed instructions on implementing this functionality in other languages and to explore comprehensive documentation on fetching transactions for a specific address, be sure to visit the official documentation page on getting transactions of an address.
Accessing Market Data: A Tutorial on Using the Mobula Blockchain API
In this tutorial, we'll guide you through the process of retrieving market data using the Mobula Blockchain API. Leveraging this premier Web3 development tool, you can access the necessary information in three simple steps:
- Obtain a Mobula API key
- Develop a script to Use the market/data endpoint
- Execute the script
Before you proceed with querying the market/data
endpoint, ensure you've covered all the prerequisites.
Prerequisites
For this tutorial on accessing market data with the Mobula Blockchain API using JavaScript, you'll need to have the following setup:
- Node.js version 16 or later
- NPM or Yarn package manager
Step 1: Obtain a Mobula API Key
To utilize the Blockchain API and the market/data
endpoint, a Mobula API key is essential. To acquire this key, you must first have a Mobula account. If you haven't set up your account yet, go to the API Dashboard to begin the process.
Create an account by filling in the registration form, if you haven't already done so. Once you've done that, you can click the "Create an API key" button. You'll just have to give it the name you want, and your first key will be created!
Ensure to keep your Mobula API key handy, as you'll need it for the next steps in this tutorial.
Step 2: Creating a Script to Retrieve Market Data Using the Mobula API
For this step, initiate a new project in your preferred Integrated Development Environment (IDE). Then, open a new terminal window in your project's root directory and execute the following command to set up your environment for using the Mobula SDK:
npm install mobula-sdk
Next, establish a new file named "index.js" in your project directory and incorporate the subsequent code snippet into it:
const {Mobula} = require('mobula-sdk');
const mobula = new Mobula('MOBULA_API_KEY');
mobula
.fetchAssetMarketData({
asset: 'Bitcoin',
})
.then(response => {
console.log(response);
})
.catch(error => {
console.error('Error:', error);
});
Then, make a minor adjustment to the code by substituting MOBULA_API_KEY
with the key you obtained in the previous step to initialize the Mobula API:
Next, adjust the asset
constant to align with the specific market data you're aiming to query:
You're all set to execute the script now!
Step 3: Run the Script
For this last step, open a terminal, navigate to your project's root directory, and execute the command below:
node index.js
Executing the command will run your script, and as a result, you'll receive comprehensive market data. This includes key information such as the current price, trading volume, liquidity metrics, and other relevant details for the asset you queried. Here's an example of what the output might resemble, tailored to market data:
data: {
market_cap: 1248979717233,
market_cap_diluted: 1341740018950,
liquidity: 230430262,
price: 63892.381854763364,
off_chain_volume: 45679496179,
volume: 365833728,
volume_change_24h: -40.43559265136719,
volume_7d: 365833728,
is_listed: true,
price_change_24h: -3.8257005,
price_change_1h: 1.1633976,
price_change_7d: 1.4587651,
price_change_1m: 24.87928,
price_change_1y: 124.04594,
ath: 73426.18983181914,
atl: 67.809,
name: 'Bitcoin',
symbol: 'BTC',
logo: 'https://metacore.mobula.io/ea67a92c8e0a9b951d6fafed56e8ee714180e9ccbadb7d0555b9cb1b1224dba7.png',
rank: 1,
contracts: [Array]
}
Congratulations! You've completed this blockchain API tutorial and have mastered the process of retrieving market data using the Mobula API.
This example serves as a foundation for utilizing other Mobula API endpoints. By making minor adjustments to the code, you can leverage various endpoints to access different types of blockchain data.
To explore all available endpoints and further enhance your understanding of the Mobula Blockchain API, refer to the official documentation page. Happy coding!
Summary: Market Data API Example and Tutorial
In this tutorial, we delved into the Mobula Blockchain API, a leading solution for accessing and integrating market data into Web3 projects. This powerful tool provides comprehensive market insights, including asset prices, trading volumes, liquidity metrics, and more, across various blockchain networks.
Highlighted by its versatility and support for major chains, Mobula stands out as the premier choice among blockchain API providers.
Furthermore, we demonstrated how to utilize the Mobula API to retrieve market data in three simple steps:
- Obtain a Mobula API key
- Develop a script to Use the market/data endpoint
- Execute the script
By following these steps, you now possess the skills to seamlessly access and integrate market data into your Web3 projects using the Mobula Blockchain API.
If you found this Market Data API tutorial helpful, explore more informative guides on our blog. Dive into topics such as "Streaming Real-time Trades via WebSocket in Multiple Languages". Additionally, don't miss out on the opportunity to sign up with Mobula. With a free account, you'll gain instant access to all cutting-edge tools, including the Market Data API!