Are you on the lookout for the simplest solution to construct decentralized purposes (dapps) for the Moonbeam community? If that’s the case, you then’re precisely the place you must be. At this time’s information introduces you to Moralis’ Web3 API suite, that includes full Moonbeam assist. With our toolkit at your fingertips, you possibly can seamlessly fetch every part from pockets balances to token costs with a single line of code. To provide you a little bit sneak peek of what’s to come back, try three of our endpoints down under, highlighting the accessibility of Moralis:
getNativeBalance() – Get the native steadiness of any crypto pockets: const response = await Moralis.EvmApi.steadiness.getNativeBalance({
“chain”: “0x504”,
“tackle”: “0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee”
});//response
{
steadiness: ‘78795103794561371347’
} getTokenPrice() – Fetch the value of any token: const response = await Moralis.EvmApi.token.getTokenPrice({
“chain”: “0x504”,
“tackle”: “0xE57eBd2d67B462E9926e04a8e33f01cD0D64346D”
});//response
{
tokenName: ‘Wrapped BTC’,
tokenSymbol: ‘WBTC’,
tokenLogo: null,
tokenDecimals: ‘8’,
nativePrice: {
worth: ‘213247794381662405144261’,
decimals: 18,
title: ‘Moonbeam’,
image: ‘GLMR’,
tackle: ‘0xacc15dc74880c9944775448304b263d191c6077f’
},
usdPrice: 62888.204126993354,
usdPriceFormatted: ‘62888.204126993356304930’,
exchangeName: ‘StellaSwap’,
exchangeAddress: ‘0x68A384D826D3678f78BB9FB1533c7E9577dACc0E’,
tokenAddress: ‘0xe57ebd2d67b462e9926e04a8e33f01cd0d64346d’,
priceLastChangedAtBlock: ‘6102802’,
verifiedContract: false
} getNFTMetadata() – Question the metadata of any NFT: const response = await Moralis.EvmApi.nft.getNFTMetadata({
“chain”: “0x504”,
“tackle”: “0x02A6DeC99B2Ca768D638fcD87A96F6069F91287c”,
“tokenId”: “1”
});//response
{
quantity: ‘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,
tackle: ‘0x931715fee2d06333043d11f658c8ce934ac61d0c’,
block_hash: ‘0xb83f55299cfc42de0400f2a800cf59d3937482d98988555bb04e964946180103’,
block_number: ‘5856925’,
block_timestamp: ‘2024-04-02T12:02:42.000Z’,
transaction_hash: ‘0xe3130e582a24525b2ebd2b35122b905448112f8901f564b2077b5bb401c08efd’,
transaction_index: 8,
log_index: 35,
worth: ‘10004’,
possible_spam: false,
value_decimal: ‘0.010004’,
verified_contract: false
},
//…
]
Token API
The Token API is the premier software for ERC-20 knowledge, supporting each single cryptocurrency throughout all main chains. This contains meme cash like Shiba Inu, stablecoins like USDT, and every part in between. With only one endpoint, you possibly can effortlessly fetch token balances, costs, metadata, and rather more, making certain that each one your token-related knowledge wants are lined!
To demo the Token API, we’ll now discover three distinguished endpoints you’ll probably discover helpful when constructing dapps for the Moonbeam community:
getWalletTokenBalances() – Get the token balances of any pockets: const response = await Moralis.EvmApi.token.getWalletTokenBalances({
“chain”: “0x504”,
“tackle”: “0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee”
});//response
{
token_address: ‘0xacc15dc74880c9944775448304b263d191c6077f’,
image: ‘WGLMR’,
title: ‘Wrapped GLMR’,
brand: null,
thumbnail: null,
decimals: 18,
steadiness: ‘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 value of any token: const response = await Moralis.EvmApi.token.getTokenPrice({
“chain”: “0x504”,
“tackle”: “0xE57eBd2d67B462E9926e04a8e33f01cD0D64346D”
});//response
{
tokenName: ‘Wrapped BTC’,
tokenSymbol: ‘WBTC’,
tokenLogo: null,
tokenDecimals: ‘8’,
nativePrice: {
worth: ‘213247794381662405144261’,
decimals: 18,
title: ‘Moonbeam’,
image: ‘GLMR’,
tackle: ‘0xacc15dc74880c9944775448304b263d191c6077f’
},
usdPrice: 62888.204126993354,
usdPriceFormatted: ‘62888.204126993356304930’,
exchangeName: ‘StellaSwap’,
exchangeAddress: ‘0x68A384D826D3678f78BB9FB1533c7E9577dACc0E’,
tokenAddress: ‘0xe57ebd2d67b462e9926e04a8e33f01cd0d64346d’,
priceLastChangedAtBlock: ‘6102802’,
verifiedContract: false
} getTokenMetadataBySymbol() – Question the metadata of any token based mostly on the image: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: [],
hyperlinks: {}
}
]
NFT API
The NFT API is the {industry}’s main software for NFT knowledge, supporting greater than three million NFT collections throughout all the most important chains. This contains every part from well-established initiatives like CryptoPunks to tokens that dropped on Moonbeam simply seconds in the past. With this industry-leading interface, you will get NFT balances, metadata, transfers, and rather more with simply single API calls!
To focus on the accessibility of the NFT API, we’ll now have a look at three distinguished endpoints that you should utilize when constructing dapps for the Moonbeam community:
getWalletNFTs() – Get the NFT steadiness of any cryptocurrency pockets: const response = await Moralis.EvmApi.nft.getWalletNFTs({
“chain”: “0x504”,
“tackle”: “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”,
“tackle”: “0x02A6DeC99B2Ca768D638fcD87A96F6069F91287c”,
“tokenId”: “1”
});//response
{
quantity: ‘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 distinguished Moralis APIs. For those who’d prefer to discover all our interfaces, be happy to take a look at our official Web3 API web page for extra data!
3-Step Tutorial: Easy methods to Construct Dapps on the Moonbeam Community Utilizing Moralis’ API Suite
Now that you’ve familiarized your self with the ins and outs of Moralis’ API suite, we’ll briefly stroll you thru a tutorial on easy methods to fetch knowledge from Moonbeam utilizing our top-tier interfaces. To take action, we’ll present you easy methods to get the native steadiness of any Moonbeam pockets utilizing our Pockets API in three easy steps:
Signal Up with MoralisWrite a Script Calling the getNativeBalance() EndpointRun the Code
Nonetheless, earlier than you possibly can proceed, you must maintain a couple of conditions!
Stipulations
For this tutorial, we’ll be utilizing JavaScript and Node.js. As such, earlier than you proceed, be sure to have the next prepared:
Step 1: Signal Up with Moralis
Click on on the ”Begin for Free” button on the high proper of Moralis’ homepage and join:
Subsequent, log in and replica your Moralis API key:
Preserve the important thing for now, as you’ll want it in step two to initialize Moralis.
Step 2: Write a Script Calling the getNativeBalance() Endpoint
Open your most well-liked IDE, arrange a folder, and initialize a brand new venture with the next terminal command:
npm init
Subsequent, set up the required dependencies with this terminal enter:
npm set up moralis @moralisweb3/common-evm-utils
From right here, add ”sort”: ”module” to your ”bundle.json” file:
Subsequent, arrange a brand new ”index.js” file and add the next code:
import Moralis from ‘moralis’;
strive {
await Moralis.begin({
apiKey: “YOUR_API_KEY”
});
const response = await Moralis.EvmApi.steadiness.getNativeBalance({
“chain”: “0x504”,
“tackle”: “0x7e9a4e275d8c5e66d7cc58e11f5ae24cc79cd1ee”
});
console.log(response.uncooked);
} catch (e) {
console.error(e);
}
From right here, you must make some minor configurations to the code. To begin with, substitute YOUR_API_KEY with the important thing you copied throughout step one:
You then additionally have to configure the tackle parameter to suit your question:
That’s it; all that continues to be now could be working the script.
Step 3: Run the Code
Open a brand new terminal, cd into the foundation folder of your venture, and execute the command under:
node index.js
In return for working the script, you’ll get the native steadiness of the pockets in query. Right here’s an instance of what it’d appear to be:
steadiness: ‘78795103794561371347’
That’s it; getting on-chain knowledge from Moonbeam doesn’t should be more difficult than this when utilizing Moralis’ Web3 API suite. From right here, now you can observe the identical steps and ideas to name any of our different endpoints. As such, when leveraging Moralis, it has by no means been simpler to construct dapps for the Moonbeam community!
Abstract: How To Construct Dapps on Moonbeam Community with Moralis’ API Suite
Moonbeam is a distinguished parachain that mixes the facility of Ethereum and Polkadot. It options full EVM compatibility, permitting you to construct dapps for the Moonbeam community with acquainted instruments. What’s extra, the community is optimized for value effectivity and efficiency, making Web3 improvement accessible to anybody!
However what’s the best solution to construct dapps for the Moonbeam community?
The reply to the above query is Moralis!
Moralis is the {industry}’s main Web3 infrastructure supplier. In our suite of Moonbeam-compatible APIs, you’ll discover over ten use case-specific interfaces. Listed here are three distinguished examples:
Pockets API: The Pockets API is the perfect software for anybody constructing cryptocurrency wallets or integrating pockets performance into Moonbeam dapps. With only one line of code, you should utilize this interface to fetch a pockets’s balances, internet value, historical past, and extra. Token API: Moralis’ Token API is the Web3 improvement {industry}’s #1 software for ERC-20 knowledge. With only one line of code, you should utilize this API to get token balances, metadata, costs, and many others. As such, that is the proper software for anybody seeking to construct dapps like DEXs or token explorers on Moonbeam. NFT API: The NFT API is Web3’s premier software for NFT knowledge. Use this interface to get NFT balances, real-time metadata, transfers, and extra. It’s the final word API for anybody seeking to construct NFT-based initiatives.
For those who preferred this Moonbeam tutorial, think about trying out extra instruments right here at Moralis. Along with top-tier APIs, we additionally provide industry-leading nodes for all main chains, together with Moonbeam.
Additionally, in the event you want to entry our nodes and premier APIs, make sure that to register an account with Moralis. You possibly can join free, and also you’ll acquire quick entry to our industry-leading improvement instruments so you possibly can construct dapps for the Moonbeam community extra effectively!