Are you looking for the easiest way to build decentralized applications (dapps) for the Moonbeam network? If so, then you’re exactly where you need to be. Today’s guide introduces you to Moralis’ Web3 API suite, featuring full Moonbeam support. With our toolkit at your fingertips, you can seamlessly fetch everything from wallet balances to token prices with a single line of code. To give you a little sneak peek of what’s to come, check out three of our endpoints down below, highlighting the accessibility of Moralis:
getNativeBalance()
– Get the native balance of any crypto wallet:
const response = await Moralis.EvmApi.balance.getNativeBalance({ "chain": "0x504", "address": "0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee" });
//response { balance: '78795103794561371347' }
getTokenPrice()
– Fetch the price of any token:
const response = await Moralis.EvmApi.token.getTokenPrice({ "chain": "0x504", "address": "0xE57eBd2d67B462E9926e04a8e33f01cD0D64346D" });
//response { tokenName: 'Wrapped BTC', tokenSymbol: 'WBTC', tokenLogo: null, tokenDecimals: '8', nativePrice: { value: '213247794381662405144261', decimals: 18, name: 'Moonbeam', symbol: 'GLMR', address: '0xacc15dc74880c9944775448304b263d191c6077f' }, usdPrice: 62888.204126993354, usdPriceFormatted: '62888.204126993356304930', exchangeName: 'StellaSwap', exchangeAddress: '0x68A384D826D3678f78BB9FB1533c7E9577dACc0E', tokenAddress: '0xe57ebd2d67b462e9926e04a8e33f01cd0d64346d', priceLastChangedAtBlock: '6102802', verifiedContract: false }
getNFTMetadata()
– Query the metadata of any NFT:
const response = await Moralis.EvmApi.nft.getNFTMetadata({ "chain": "0x504", "address": "0x02A6DeC99B2Ca768D638fcD87A96F6069F91287c", "tokenId": "1" });
//response { amount: '1', token_id: '1', token_address: '0x02a6dec99b2ca768d638fcd87a96f6069f91287c', contract_type: 'ERC721', owner_of: '0xd32bf73490aeb32c078ee24911634c06d605a67b', last_metadata_sync: '2024-05-07T08:29:54.453Z', last_token_uri_sync: '2024-05-07T08:29:54.209Z', metadata: '{"attributes":[{"trait_type":"Name","value":"G0000454"},{"trait_type":"Type","value":"Beast"},{"trait_type":"Rarity","value":"Common"},{"trait_type":"Social","value":10}' //..., block_number: '1706718', block_number_minted: null, name: 'MoonFit Beast and Beauty', symbol: 'MFBB', token_hash: 'f5b5c0d66260fc88d0607946c967f352', token_uri: 'https://prod-cdn.moonfit.xyz/metadata/1.json', minter_address: null, verified_collection: false, possible_spam: false, collection_logo: null, collection_banner_image: null }
Querying on-chain data from the Moonbeam network when using Moralis’ API suite is easy. Now, if you’d like to learn more about our APIs and how to use them, make sure to follow along in this guide!
Also, did you know you can sign up with Moralis for free? Doing so will give you immediate access to our Moonbeam-compatible Web3 API suite, so you can start building comprehensive dapps for the network today!
Overview: Build Dapps with a Moonbeam API
While Ethereum remains Web3’s most significant platform for dapp development, it’s no secret that the network has been plagued by high transaction fees, making it expensive to transact on the chain. As a result, developers are increasingly exploring other networks. And one notable option currently gaining traction is Moonbeam!
But what exactly is Moonbeam? And how do you build dapps for the Moonbeam network? If you’re looking for the answers to these queries, join us in this guide as we dive deeper into the Moonbeam ecosystem and explore the best APIs for building dapps on the network. It doesn’t matter whether you’re building a decentralized exchange (DEX), cryptocurrency wallet, or any other Web3 project; this read is for you. Let’s dive straight in!
What is Moonbeam Network?
Moonbeam was introduced in December 2021, and it is a delegated proof-of-stake (DPoS) EVM-compatible parachain that combines the power of Ethereum and Polkadot, seamlessly bringing Solidity smart contracts into the ecosystem. As such, Moonbeam makes it possible for you to build cross-chain connected dapps that leverage unique assets and functionality from many blockchain networks simultaneously!
To better understand Moonbeam, let’s explore four prominent benefits of this blockchain network:
- Enhanced Developer Experience: Moonbeam features broad compatibility with Ethereum tools, making the transition from Ethereum into the Polkadot ecosystem a breeze. Some examples of tools include MetaMask, Hardhat, Remix, Truffle, and many others.
- High-Performance and Cost-Effective: Moonbeam is optimized for both performance and cost-efficiency. It combines Polkadot’s scalability capabilities with low gas fees, making Moonbeam a significantly more economically viable option to chains like Ethereum. These lower gas fees attract a diverse user base, giving you a significant opportunity to grow your project.
- EVM and Polkadot Compatibility: Moonbeam combines the best of two worlds: Ethereum and Polkadot. This allows you to seamlessly migrate and deploy Ethereum dapps on Polkadot without any major code configurations.
- Seamless Multi-Chain Integration: As a parachain, Moonbeam facilitates seamless cross-chain communication within the Polkadot ecosystem, extending the reach and functionality of your Web3 projects.
That gives you an overview of Moonbeam. Let’s now explore the ecosystem further by diving into Glimmer!
What is the Glimmer Token?
Glimmer is the native token of the Moonbeam network, and it plays a vital part in the ecosystem. In fact, Glimmer has several prominent use cases, and we’ll explore four prominent examples down below:
- Transaction Fees: Glimmer is the token used to pay for transactions on the network. As such, it’s vital for anyone interacting with the network, including users and Web3 developers looking to build dapps on Moonbeam.
- On-Chain Governance: Glimmer is a vital part of Moonbeam’s on-chain governance. Holders of Glimmer can vote on important matters, propose changes to the protocol, and elect council members for the ecosystem.
- Incentivizing Collators: Glimmer is used to incentivize collators and power the mechanism surrounding the creation of the decentralized node structure that supports the Moonbeam ecosystem.
- Gas Metering: Gas is measured and calculated in Glimmer for the Moonbeam blockchain network.
That covers the basics of the network. In the next section, we’ll dive into Moralis’ API suite – the easiest way to build dapps for the Moonbeam network!
Build Dapps on the Moonbeam Network with Moralis’ API Suite
The easiest way to build dapps on the Moonbeam network is to leverage Moralis – the industry’s leading Web3 API provider. In our suite of development tools, you’ll find over ten use case-specific APIs you can use for Moonbeam development, including the Wallet API, Token API, NFT API, and many others. As such, it doesn’t matter if you’re building a cryptocurrency wallet, decentralized exchange (DEX), or any other dapps for the Moonbeam network; we’ve got your data needs covered!
So, why should you leverage Moralis’ API suite to build dapps for the Moonbeam network?
To answer this question, let’s explore three benefits of our premier interfaces!
- One Request – All the Data: Our APIs are designed with the outcome in mind, giving you more data with fewer requests. Get data from multiple on-chain and off-chain sources with a single endpoint, minimizing the API calls needed to build comprehensive dapps for the Moonbeam network.
- Cross-Chain Compatibility: Streamline your developer experience by removing the need to integrate a new provider for each chain. Build cross-chain dapps with APIs that support all major networks, including Moonbeam, Ethereum, Polygon, BNB Smart Chain (BSC), and many others.
- Enterprise-Grade Security: Experience the gold standard for enterprise-grade data security with Moralis – the only SOC 2 Type 2 certified Web3 infrastructure provider.
That covers the basics of Moralis. Let’s now dive a bit deeper and explore three APIs you’ll likely find helpful in your Moonbeam development endeavors!
Wallet API
Moralis’ Wallet API stands out as the industry’s premier interface for wallet data, supporting over 500 million addresses across all major chains. With single lines of code, you can effortlessly fetch any wallet’s token balances, history, net worth, profitability, and much more. As such, when leveraging the Wallet API, you can build wallets or integrate wallet functionality into your Moonbeam dapps without breaking a sweat!
To highlight the power of the Wallet API, we’ll explore three prominent endpoints you’ll likely find helpful when building dapps for the Moonbeam network:
getNativeBalance()
– Fetch the native balance of any address:
const response = await Moralis.EvmApi.balance.getNativeBalance({ "chain": "0x504", "address": "0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee" });
//response { balance: '78795103794561371347' }
getWalletTokenBalances()
– Get the token balances of any address:
const response = await Moralis.EvmApi.token.getWalletTokenBalances({ "chain": "0x504", "address": "0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee" });
//response { token_address: '0xacc15dc74880c9944775448304b263d191c6077f', symbol: 'WGLMR', name: 'Wrapped GLMR', logo: null, thumbnail: null, decimals: 18, balance: '3007235543344491588', possible_spam: false, verified_contract: false, total_supply: '10753128222445016077512909', total_supply_formatted: '10753128.222445016077512909', percentage_relative_to_total_supply: 0.000027966146047319 }, //...
getWalletTokenTransfers()
– Query the transaction history of any wallet:
const response = await Moralis.EvmApi.token.getWalletTokenTransfers({ "chain": "0x504", "address": "0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee" });
//response ] { token_name: 'USD Coin', token_symbol: 'USDC', token_logo: null, token_decimals: '6', from_address: '0x1ff2adaa387dd27c22b31086e658108588eda03a', from_address_label: null, to_address: '0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee', to_address_label: null, address: '0x931715fee2d06333043d11f658c8ce934ac61d0c', block_hash: '0xb83f55299cfc42de0400f2a800cf59d3937482d98988555bb04e964946180103', block_number: '5856925', block_timestamp: '2024-04-02T12:02:42.000Z', transaction_hash: '0xe3130e582a24525b2ebd2b35122b905448112f8901f564b2077b5bb401c08efd', transaction_index: 8, log_index: 35, value: '10004', possible_spam: false, value_decimal: '0.010004', verified_contract: false }, //... ]
Token API
The Token API is the premier tool for ERC-20 data, supporting every single cryptocurrency across all major chains. This includes meme coins like Shiba Inu, stablecoins like USDT, and everything in between. With just one endpoint, you can effortlessly fetch token balances, prices, metadata, and much more, ensuring that all your token-related data needs are covered!
To demo the Token API, we’ll now explore three prominent endpoints you’ll most likely find useful when building dapps for the Moonbeam network:
getWalletTokenBalances()
– Get the token balances of any wallet:
const response = await Moralis.EvmApi.token.getWalletTokenBalances({ "chain": "0x504", "address": "0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee" });
//response { token_address: '0xacc15dc74880c9944775448304b263d191c6077f', symbol: 'WGLMR', name: 'Wrapped GLMR', logo: null, thumbnail: null, decimals: 18, balance: '3007235543344491588', possible_spam: false, verified_contract: false, total_supply: '10753128222445016077512909', total_supply_formatted: '10753128.222445016077512909', percentage_relative_to_total_supply: 0.000027966146047319 }, //...
getTokenPrice()
– Fetch the price of any token:
const response = await Moralis.EvmApi.token.getTokenPrice({ "chain": "0x504", "address": "0xE57eBd2d67B462E9926e04a8e33f01cD0D64346D" });
//response { tokenName: 'Wrapped BTC', tokenSymbol: 'WBTC', tokenLogo: null, tokenDecimals: '8', nativePrice: { value: '213247794381662405144261', decimals: 18, name: 'Moonbeam', symbol: 'GLMR', address: '0xacc15dc74880c9944775448304b263d191c6077f' }, usdPrice: 62888.204126993354, usdPriceFormatted: '62888.204126993356304930', exchangeName: 'StellaSwap', exchangeAddress: '0x68A384D826D3678f78BB9FB1533c7E9577dACc0E', tokenAddress: '0xe57ebd2d67b462e9926e04a8e33f01cd0d64346d', priceLastChangedAtBlock: '6102802', verifiedContract: false }
getTokenMetadataBySymbol()
– Query the metadata of any token based on the symbol:
const response = await Moralis.EvmApi.token.getTokenMetadataBySymbol({ "chain": "0x504", "symbols": [ "GLMR" ] });
//response [ { address: '0xa5f2aa399336d13495d872fce8b1de08cb29aabe', address_label: null, name: 'Moonbeam', symbol: 'GLMR', decimals: '18', logo: null, logo_hash: null, thumbnail: null, total_supply: '1010000000000000000000', total_supply_formatted: '1010', fully_diluted_valuation: '0', block_number: '5411412', validated: 1, created_at: '2024-01-30T11:28:24.000Z', possible_spam: false, verified_contract: false, categories: [], links: {} } ]
NFT API
The NFT API is the industry’s leading tool for NFT data, supporting more than three million NFT collections across all the biggest chains. This includes everything from well-established projects like CryptoPunks to tokens that dropped on Moonbeam just seconds ago. With this industry-leading interface, you can get NFT balances, metadata, transfers, and much more with just single API calls!
To highlight the accessibility of the NFT API, we’ll now look at three prominent endpoints that you can use when building dapps for the Moonbeam network:
getWalletNFTs()
– Get the NFT balance of any cryptocurrency wallet:
const response = await Moralis.EvmApi.nft.getWalletNFTs({ "chain": "0x504", "address": "0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee" });
//response [ { amount: '1', token_id: '888', token_address: '0x3a82f4da24f93a32dc3c2a28cfa9d6e63ec28531', contract_type: 'ERC721', owner_of: '0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee', last_metadata_sync: '2024-05-07T10:13:18.846Z', last_token_uri_sync: '2024-05-07T10:13:18.654Z', metadata: '{"name":"GLMR MAI Vault","description":"Moonbeam GLMR MAI Vault","image":"QmcKGKPdmEKp3NUevnaRZjnvSCJfgnGPw8wkANaut2yH7H"}', block_number: '5662776', block_number_minted: null, name: 'GLMR MAI Vault', symbol: 'GMVT', token_hash: '0204ea2b853198d0ecc2cb33e9f6de4e', token_uri: 'https://ipfs.moralis.io:2053/ipfs/QmZ8eAAh1xHBFaq8P6uKGc8kZ5VcAhcpA9FRkqJbGB7Xhd', minter_address: null, verified_collection: false, possible_spam: false, collection_logo: null, collection_banner_image: null }, //... ]
getNFTMetadata()
– Fetch the metadata of any NFT:
const response = await Moralis.EvmApi.nft.getNFTMetadata({ "chain": "0x504", "address": "0x02A6DeC99B2Ca768D638fcD87A96F6069F91287c", "tokenId": "1" });
//response { amount: '1', token_id: '1', token_address: '0x02a6dec99b2ca768d638fcd87a96f6069f91287c', contract_type: 'ERC721', owner_of: '0xd32bf73490aeb32c078ee24911634c06d605a67b', last_metadata_sync: '2024-05-07T08:29:54.453Z', last_token_uri_sync: '2024-05-07T08:29:54.209Z', metadata: '{"attributes":[{"trait_type":"Name","value":"G0000454"},{"trait_type":"Type","value":"Beast"},{"trait_type":"Rarity","value":"Common"},{"trait_type":"Social","value":10}' //..., block_number: '1706718', block_number_minted: null, name: 'MoonFit Beast and Beauty', symbol: 'MFBB', token_hash: 'f5b5c0d66260fc88d0607946c967f352', token_uri: 'https://prod-cdn.moonfit.xyz/metadata/1.json', minter_address: null, verified_collection: false, possible_spam: false, collection_logo: null, collection_banner_image: null }
getWalletNFTTransfers()
– Query an array of a wallet’s historical NFT transfers:
const response = await Moralis.EvmApi.nft.getWalletNFTTransfers({ "chain": "0x504", "address": "0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee" });
//response [ { block_number: '5549493', block_timestamp: '2024-02-18T23:53:54.000Z', block_hash: '0xc2b8958d045bedc86c5a7576394e129a41a5d0e1ec15ed3752303587cb06ac3e', transaction_hash: '0xf0311fb459cda24cb80ba68bcae471e953e89e46facddd135e6785a5ff48fe17', transaction_index: 5, log_index: 10, value: '9999999998838665141', contract_type: 'ERC721', transaction_type: 'Single', token_address: '0x1ff2adaa387dd27c22b31086e658108588eda03a', token_id: '39098', from_address: '0x0000000000000000000000000000000000000000', from_address_label: null, to_address: '0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee', to_address_label: null, amount: '1', verified: 1, operator: null, possible_spam: false, verified_collection: false }, //... ]
That covers three prominent Moralis APIs. If you’d like to explore all our interfaces, feel free to check out our official Web3 API page for more information!
3-Step Tutorial: How to Build Dapps on the Moonbeam Network Using Moralis’ API Suite
Now that you have familiarized yourself with the ins and outs of Moralis’ API suite, we’ll briefly walk you through a tutorial on how to fetch data from Moonbeam using our top-tier interfaces. To do so, we’ll show you how to get the native balance of any Moonbeam wallet using our Wallet API in three straightforward steps:
- Sign Up with Moralis
- Write a Script Calling the
getNativeBalance()
Endpoint - Run the Code
However, before you can continue, you need to take care of a few prerequisites!
Prerequisites
For this tutorial, we’ll be using JavaScript and Node.js. As such, before you proceed, make sure you have the following ready:
Step 1: Sign Up with Moralis
Click on the ”Start for Free” button at the top right of Moralis’ homepage and sign up:
Next, log in and copy your Moralis API key:
Keep the key for now, as you’ll need it in step two to initialize Moralis.
Step 2: Write a Script Calling the getNativeBalance()
Endpoint
Open your preferred IDE, set up a folder, and initialize a new project with the following terminal command:
npm init
Next, install the required dependencies with this terminal input:
npm install moralis @moralisweb3/common-evm-utils
From here, add ”type”: ”module”
to your ”package.json” file:
Next, set up a new ”index.js” file and add the following code:
import Moralis from 'moralis'; try { await Moralis.start({ apiKey: "YOUR_API_KEY" }); const response = await Moralis.EvmApi.balance.getNativeBalance({ "chain": "0x504", "address": "0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee" }); console.log(response.raw); } catch (e) { console.error(e); }
From here, you need to make some minor configurations to the code. First of all, replace YOUR_API_KEY
with the key you copied during the first step:
You then also need to configure the address
parameter to fit your query:
That’s it; all that remains now is running the script.
Step 3: Run the Code
Open a new terminal, cd
into the root folder of your project, and execute the command below:
node index.js
In return for running the script, you’ll get the native balance of the wallet in question. Here’s an example of what it might look like:
balance: '78795103794561371347'
That’s it; getting on-chain data from Moonbeam doesn’t have to be more challenging than this when using Moralis’ Web3 API suite. From here, you can now follow the same steps and principles to call any of our other endpoints. As such, when leveraging Moralis, it has never been easier to build dapps for the Moonbeam network!
Summary: How To Build Dapps on Moonbeam Network with Moralis’ API Suite
Moonbeam is a prominent parachain that combines the power of Ethereum and Polkadot. It features full EVM compatibility, allowing you to build dapps for the Moonbeam network with familiar tools. What’s more, the network is optimized for cost efficiency and performance, making Web3 development accessible to anyone!
But what is the easiest way to build dapps for the Moonbeam network?
The answer to the above question is Moralis!
Moralis is the industry’s leading Web3 infrastructure provider. In our suite of Moonbeam-compatible APIs, you’ll find over ten use case-specific interfaces. Here are three prominent examples:
- Wallet API: The Wallet API is the ideal tool for anyone building cryptocurrency wallets or integrating wallet functionality into Moonbeam dapps. With just one line of code, you can use this interface to fetch a wallet’s balances, net worth, history, and more.
- Token API: Moralis’ Token API is the Web3 development industry’s #1 tool for ERC-20 data. With just one line of code, you can use this API to get token balances, metadata, prices, etc. As such, this is the perfect tool for anyone looking to build dapps like DEXs or token explorers on Moonbeam.
- NFT API: The NFT API is Web3’s premier tool for NFT data. Use this interface to get NFT balances, real-time metadata, transfers, and more. It’s the ultimate API for anyone looking to build NFT-based projects.
If you liked this Moonbeam tutorial, consider checking out more tools here at Moralis. In addition to top-tier APIs, we also offer industry-leading nodes for all major chains, including Moonbeam.
Also, if you wish to access our nodes and premier APIs, make sure to register an account with Moralis. You can sign up for free, and you’ll gain immediate access to our industry-leading development tools so you can build dapps for the Moonbeam network more efficiently!
Read More: moralis.io