In today’s tutorial, we’ll explore Moonbeam and the network’s benefits to explain why you might want to build on the chain. In combination with this, we’ll also introduce you to Moralis – the industry’s leading crypto data provider. With our top-tier RPC nodes and APIs, you can fetch and integrate on-chain data from Moonbeam into your Web3 projects without breaking a sweat. If you’re eager to learn how this works, check out the example below, which highlights how easy it is to fetch token prices with Moralis: 

import fetch from 'node-fetch';

const options = {
  method: 'GET',
  headers: {
    accept: 'application/json',
    'X-API-Key': 'YOUR_API_KEY'
  },
};

fetch('https://deep-index.moralis.io/api/v2.2/erc20/0xE57eBd2d67B462E9926e04a8e33f01cD0D64346D/price?chain=0x504&include=percent_change', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

In return for calling the script above, you’ll get the price of the specified token denominated in both the chain’s native currency and USD. Here’s an example of what it might look like: 

{
  tokenName: 'Wrapped BTC',
  tokenSymbol: 'WBTC',
  tokenLogo: null,
  tokenDecimals: '8',
  nativePrice: {
    value: '361716720517110579889317',
    decimals: 18,
    name: 'Moonbeam',
    symbol: 'GLMR',
    address: '0xacc15dc74880c9944775448304b263d191c6077f'
  },
  usdPrice: 57333.47928669679,
  usdPriceFormatted: '57333.479286696792189825',
  exchangeName: 'StellaSwap',
  exchangeAddress: '0x68A384D826D3678f78BB9FB1533c7E9577dACc0E',
  tokenAddress: '0xe57ebd2d67b462e9926e04a8e33f01cd0d64346d',
  priceLastChangedAtBlock: '7395637',
  blockTimestamp: '1725934212000',
  possibleSpam: false,
  verifiedContract: false,
  pairAddress: '0xf8f5e8b9ee84664695b14862212d8092e16331f6',
  pairTotalLiquidityUsd: '6512.06',
  '24hrPercentChange': '4.2813011084629755',
  securityScore: 64
}

That’s it; fetching on-chain data from Moonbeam doesn’t have to be more challenging than this. For a more in-depth tutorial and further insight into our development tools, join us in this article as we lay it all out for you. 

Ready to immediately start using our APIs and RPC nodes? Sign up for free with Moralis! 

Overview

Ethereum has been the most prominent blockchain for decentralized application (dapp) development for a while; however, the network has been struggling with high transaction fees, making it economically unviable for many to interact with the chain. This has opened the space for alternative networks, and a great example that’s been gaining popularity is Moonbeam.

Moonbeam logo.

But what is Moonbeam? How does it work? And why should you build on the Moonbeam network? If you’re looking for the answers to these questions, then you’ll definitely want to join us in this article. Let’s dive straight in!

What is Moonbeam? And Why Build on the Moonbeam Network?

Moonbeam launched back in December 2021 as a delegated proof-of-stake (DPoS) EVM-compatible parachain, combining the power of Polkadot and Ethereum to seamlessly integrate Solidity smart contracts into the ecosystem. This allows you to seamlessly create cross-chain dapps that leverage unique assets and functionality from multiple networks simultaneously!

Text: "What is Moonbeam Network?"

Why Build on Moonbeam?

There are several reasons why you should build on Moonbeam. Here are four key benefits of the network:

  • Cost-Effective & High-Performance: The Moonbeam network is optimized for cost-efficiency and high performance. This is possible because the chain combines Polkadot’s scalability capabilities with low gas fees, making Moonbeam a more economically friendly alternative to networks like Ethereum.
  • Seamless Developer Experience: As an EVM chain, Moonbeam is highly compatible with Ethereum tools, making the switch from Ethereum to the Polkadot ecosystem a breeze. Tools you can use include MetaMask, Remix, Truffle, and more.
  • Multi-Chain Capabilities: Since Moonbeam is a parachain, it facilitates seamless cross-chain communication within Polkadot’s ecosystem, extending the functionality and reach of your Web3 projects.
  • EVM & Polkadot Compatibility: With EVM and Polkadot compatibility, you can seamlessly migrate and deploy existing Ethereum projects on Polkadot without significant code changes.

That gives you an overview of why you should build on Moonbeam. Let’s now dive a bit deeper into the Moonbeam ecosystem!

Exploring the Moonbeam Ecosystem

Moonbeam features an extensive ecosystem of promising projects. Here are three examples:

  • Moonwell: A prominent lending, borrowing, and decentralized finance (DeFi) protocol built on both Moonriver and Moonbeam. With an intuitive user interface, Moonwell ensures a streamlined user experience, enabling everyone to maximize the value of their digital assets.
  • Beamswap: A decentralized exchange (DEX) and DeFi hub that leverages a concentrated liquidity market maker (CLMM) protocol to facilitate transactions. On Beamswap, users can perform instant peer-to-peer transactions and earn rewards in exchange for supplying liquidity to the protocol.
  • SushiSwap: A DEX that allows users to seamlessly trade cryptocurrencies without intermediaries. SushiSwap leverages an automated market maker (AMM) system to facilitate peer-to-peer transactions.
Moonbeam Ecosystem.

Glimmer Token Explained

Another vital part of Moonbeam’s ecosystem is the network’s native token called Glimmer. Glimmer has multiple prominent use cases, and below, we’ll explore three of them:

  • Transaction Fees: The Glimmer token is used to pay for transactions on Moonbeam. As such, it’s crucial for anyone looking to interact with the network.
  • Gas Metering: Gas on the Moonbeam network is calculated and measured in Glimmer.
  • On-Chain Governance: The Glimmer token is an essential part of Moonbeam’s on-chain governance. Holders of Glimmer can propose changes to the protocol, vote on important matters, and elect council members for the ecosystem.

Now, that gives you an overview of the Moonbeam ecosystem. In the next section, we’ll introduce you to Moralis and our Moonbeam-compatible Web3 development tools!

Moralis x Moonbeam – Introducing the #1 Moonbeam API

Moralis is the industry’s premier Web3 data provider, featuring top-tier RPC nodes and Web3 APIs that facilitate a more streamlined developer experience. In our suite of Moonbeam-compatible Web3 development tools, you’ll find interfaces like the Wallet API, Token API, NFT API, and many more. As such, when using Moralis, you get all crypto data in one place! 

Moralis x Moonbeam.

Why Build on Moonbeam with Moralis?

But why should you build on Moonbeam with Moralis? To answer this question, let’s explore three benefits of our APIs and RPC nodes:

  • One Call – All the Data: Our APIs and Extended RPC Methods are designed with the outcome in mind, giving you more data with fewer calls. Fetch a wallet’s full history, token balances with prices, NFT metadata, and more with single requests.
  • Multi-Chain Compatibility: Moralis supports all major chains, including Moonbeam, Ethereum, Polygon, Optimism, Base, and many more. As such, when using our tools, you can streamline your developer experience as you only need a single provider for all data needs.
  • Secure & Reliable: Moralis is SOC 2 Type 2 certified, highlighting our commitment to maintaining high reliability and security.

To further highlight the benefits of Moralis, let’s dive deeper into our development tools!

Moralis Deep Dive

Moralis offers several industry-leading development tools. In the following sections, we’ll dive deeper into both our Web3 APIs and RPC nodes. Let’s go! 

Moralis Logo.

Web3 APIs

Moralis’ Web3 API suite comprises several Moonbeam-compatible interfaces. Here are five prominent examples: 

  • Wallet API: Get any wallet’s full transaction history, token balances, net worth, profitability, and more with just single API requests. This is the perfect tool for anyone looking to build wallets or integrate wallet functionality into dapps. 
  • Token API: Fetch token balances, transactions, prices, and much more without breaking a sweat. Use the Token API to seamlessly integrate ERC-20 data into your dapps. 
  • NFT API: Query NFT balances, up-to-date metadata, prices, transfers, etc., with single lines of code. Use this premier interface to build everything from NFT marketplaces to Web3 games. 
  • Price API: Get both historical and real-time prices for NFTs and ERC-20 tokens alike. Leverage the Price API to seamlessly integrate accurate and trustworthy price data into your dapps. 
  • Streams API: The industry’s leading real-time data solution, allowing you to set up Web3 data pipelines at the click of a few buttons. Use the Streams API to seamlessly integrate real-time alerts into your dapps, populate databases with data, or add current, actionable insights into your projects. 

To explore all our interfaces, please visit our Web3 API page!

RPC Nodes

Moralis is a top-tier provider of next-generation RPC nodes. With our intuitive point-and-click interface, you can seamlessly set up nodes for all major chains, including Moonbeam, Ethereum, Optimism, and many more networks! 

Moralis RPC Nodes.

But what makes our RPC nodes unique? 

  • Speed: Our nodes set the industry benchmark for speed with response times from 70 ms. 
  • Reliability: With 99.9% uptime, our RPC nodes deliver enterprise-grade reliability. 
  • Extended RPC Methods: Use Extended RPC Methods to fetch decoded, human-readable data using our next-generation RPC nodes. 

To learn more about this, check out our RPC nodes page! 

Full Tutorial: How to Get On-Chain Data from Moonbeam in 3 Steps

With an overview of what Moralis entails, we’ll now walk you through a tutorial on how to get on-chain data from Moonbeam using our APIs. More specifically, we’ll show you how to fetch the price of any token. Thanks to the accessibility of our Web3 APIs, you can get this data in three simple steps: 

  1. Get a Moralis API Key
  2. Write a Script
  3. Run the Code

But before you can keep going, you need to deal with a few prerequisites! 

Prerequisites

Make sure you have the following ready if you want to follow along with this tutorial: 

Step 1: Get a Moralis API Key

The first thing you’ll need is a Moralis account. As such, if you haven’t already, click the ”Start for Free” button at the top right to sign up with Moralis: 

Red arrow pointing at "Start for Free" button.

Once you log in, you can find your API key directly under the ”Home” tab: 

Red arrow pointing at copy button for Moralis API Key.

Copy and keep the key for now, as you’ll need it in the next step. 

Step 2: Write a Script

Open your integrated development environment (IDE), create a folder, and initialize your new project with the terminal command below: 

npm init

From here, install the required dependencies with these terminal commands: 

npm install node-fetch --save
npm install moralis @moralisweb3/common-evm-utils

Open your ”package.json” file and add ”type”: ”module” to the list: 

"type": "module" added to code.

Set up a new ”index.js” file and add the following code to it: 

import fetch from 'node-fetch';

const options = {
  method: 'GET',
  headers: {
    accept: 'application/json',
    'X-API-Key': 'YOUR_API_KEY'
  },
};

fetch('https://deep-index.moralis.io/api/v2.2/erc20/0xE57eBd2d67B462E9926e04a8e33f01cD0D64346D/price?chain=0x504&include=percent_change', options)
 .then(response => response.json())
 .then(response => console.log(response))
 .catch(err => console.error(err));

Replace YOUR_API_KEY with the key you previously copied, and configure the address parameter to fit your query: 

Code configurations.

Step 3: Run the Code

Launch a new terminal and run the command below in your project’s root folder to execute the code: 

node index.js

In return, you’ll get the price of the token denominated in both Glimmer and USD. What’s more, the response is also enriched with token logos, price changes over time, spam indicators, and much more. Here’s what it might look like: 

{
  tokenName: 'Wrapped BTC',
  tokenSymbol: 'WBTC',
  tokenLogo: null,
  tokenDecimals: '8',
  nativePrice: {
    value: '361716720517110579889317',
    decimals: 18,
    name: 'Moonbeam',
    symbol: 'GLMR',
    address: '0xacc15dc74880c9944775448304b263d191c6077f'
  },
  usdPrice: 57333.47928669679,
  usdPriceFormatted: '57333.479286696792189825',
  exchangeName: 'StellaSwap',
  exchangeAddress: '0x68A384D826D3678f78BB9FB1533c7E9577dACc0E',
  tokenAddress: '0xe57ebd2d67b462e9926e04a8e33f01cd0d64346d',
  priceLastChangedAtBlock: '7395637',
  blockTimestamp: '1725934212000',
  possibleSpam: false,
  verifiedContract: false,
  pairAddress: '0xf8f5e8b9ee84664695b14862212d8092e16331f6',
  pairTotalLiquidityUsd: '6512.06',
  '24hrPercentChange': '4.2813011084629755',
  securityScore: 64
}

That’s it; fetching data from Moonbeam doesn’t have to be more challenging than this. From here, you can now follow the same steps to call any of our other endpoints! 

What Can You Build on Moonbeam? – Exploring Use Cases

Now that you know how to get on-chain data from Moonbeam, let’s explore some prominent use cases:

  • Web3 Wallets: Web3 wallets are tools for storing and managing digital assets like NFTs and ERC-20 tokens. Moreover, wallets typically provide functionality for buying, selling, and swapping tokens. A prominent example of a wallet is MetaMask.
  • Portfolio Trackers: Portfolio trackers give users an overview of how their digital assets perform over time. A great platform offering a top-tier portfolio tracker feature is Moralis.
  • Tax Tools: Tax tools are software that helps both individuals and businesses calculate, report, and manage taxes related to cryptocurrencies. A prominent platform within the space is Koinly.
Moonbeam use cases.

Summary: Exploring Moonbeam – Why Build on Moonbeam?

Moonbeam was introduced late in 2021, and it’s a DPoS, EVM-compatible parachain combining the power of Polkadot and Ethereum. As such, the Moonbeam network enables developers to build cross-chain Web3 projects that leverage assets and functionality from multiple blockchains simultaneously.

Why build on moonbeam summary.

But why should you build on Moonbeam?

To answer the above question, let’s explore four benefits of the network:

  • Cost-Effective & High-Performance: Moonbeam is designed for high performance and cost-efficiency, making it an attractive platform for developers and end users alike.
  • Seamless Developer Experience: With EVM compatibility, you can use familiar Ethereum tools to build dapps on Moonbeam.
  • EVM & Polkadot Compatibility: Seamlessly migrate and deploy Ethereum dapps on Polkadot without dealing with major code configurations.
  • Multi-Chain Integration: As a parachain, Moonbeam facilitates easy cross-chain communication within the entire Polkadot ecosystem.

In combination with exploring Moonbeam, we also introduce the best tool for building on this blockchain network: Moralis!

Moralis logo.

Moralis is a leading Web3 data provider, giving you seamless access to top-tier RPC nodes and Web3 APIs. Some prominent examples include the Wallet API, Token API, Streams API, etc. With Moralis, you get all crypto data in one place.

But why build on Moonbeam with Moralis?

  • Comprehensive: Our API responses and Extended RPC Methods give you more data with fewer calls.
  • Multi-Chain: Moralis supports all major chains, including Moonbeam, Ethereum, Polygon, Optimism, Base, and many more.
  • Secure & Reliable: Experience enterprise-grade security and reliability with Moralis, the first SOC 2 Type 2 certified Web3 data provider.

If you liked this Moonbeam tutorial, consider checking out more premier content here at Moralis. For instance, explore our “Why Build on Chiliz” guide or discover our NFT Rarity API.

Also, if you want to use our tools yourself, don’t forget to sign up with Moralis!



Source link

Leave a Reply

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