With the rapid expansion of the Web3 industry, we have seen numerous blockchain networks emerge to address the growing demand for decentralized applications (dapps). And the fragmented ecosystem of multiple blockchains has highlighted the need for interoperability. Consequently, Web3 developers should be able to build cross-chain compatible dapps – on networks like Solana and all major EVM chains – to reach the largest possible audience. Although most developers might choose to launch on a specific network, any forward-looking Web3 project should be built with cross-chain compatible APIs, enabling future expansion to other networks. So, what APIs should these developers use? For the answer to this question, join us in this article as we show you the easiest way to build on Solana and EVM!
Overview
In today’s article, we’ll start by introducing you to Moralis and explain how you can use our tools to build on both Solana and all major EVM chains. From there, we’ll dive deeper into our cross-chain compatible APIs to highlight the capabilities of these industry-leading tools. Lastly, to top things off, we’ll cover two brief examples of how you can get the NFT balance of any address on both Solana and all EVM chains.
Also, did you know that you can access all our APIs free of charge? All you have to do is sign up with Moralis, and you’ll immediately be able to leverage the full power of blockchain technology!
Nevertheless, without further ado, let’s jump right into it and explore the easiest way to build on Solana and EVM!
How to Build on Solana and EVM
The most accessible way to build on Solana and EVM chains is to leverage Moralis’ cross-chain compatible APIs. Moralis provides a comprehensive suite of enterprise-grade APIs, making Web3 development as seamless as Web2. As such, when working with Moralis, it has never been easier to build cross-chain compatible decentralized applications (dapps)!
Among the supported networks, you’ll find Solana and ten+ EVM chains, including Ethereum, Polygon, BNB Smart Chain (BSC), Optimism, and many others!
Furthermore, not only do the cross-chain compatible APIs from Moralis allow you to build on both Solana and multiple EVM networks, but they are also the best in the business. As such, when it comes to response times, scalability, reliability, and features, Moralis APIs clearly stand out as industry leaders!
Build on Solana
With Moralis’ Solana-compatible APIs, you can effortlessly bring projects to market faster and more efficiently. The APIs index any blockchain data you need for Solana development, including data for NFTs, fungible tokens, wallets, and more!
Querying blockchain data has never been easier, and with only single lines of code, you can accomplish the following:
- Get NFT metadata
- Fetch wallet portfolios
- Query token balances by wallet
- Monitor wallet activity
- Get SPL token prices
- And more!
Moralis’ Solana-compatible APIs support the Solana mainnet and testnet, ensuring you can leverage our comprehensive suite of tools for both testing and developing production-ready dapps!
If you immediately want to build on Solana and explore all available endpoints, check out our official Solana Web3 data API documentation page.
Build on EVM
With Moralis’ EVM-compatible APIs, you can seamlessly build dapps faster and more efficiently across ten+ blockchain networks. In fact, when working with our suite of industry-leading interfaces, you can save a whopping 83% of the average Web3 go-to-market time, enabling you to prototype, deploy, and launch your Web3 projects before everyone else!
What’s more, by using Moralis APIs, you’ll be leveraging the same easy-to-use tech that already powers some of the most significant projects in Web3, including MetaMask, Delta, NFTrade, 1inch, and many others.
So, what can you do with our EVM-compatible APIs?
With only single lines of code, you can do the following:
- Query token prices
- Stream real-time blockchain data
- Get user tokens
- Monitor NFT collection prices
- Fetch NFT metadata
- And much more!
If you want to get right into it and explore all available EVM endpoints, check out our official EVM Web3 data API documentation page.
Nevertheless, that covers the basics of how you can build on Solana and EVM networks with Moralis. Let’s now dive a bit deeper and look closer at some of Moralis’ cross-chain compatible APIs!
Solana and EVM Compatible APIs
Moralis offers a range of cross-chain compatible APIs, making it the ultimate one-stop shop for anyone looking to build on both Solana and EVM chains. In this section, we’ll explore three prominent examples:
- NFT API
- Token API
- Wallet API
Nevertheless, without further delay, let’s start by diving into the NFT API!
NFT API
The Moralis NFT API is free to use and delivers unmatched performance through lightning-fast CDNs. It supports over three million NFT collections, including everything from established projects like CryptoPunks and Pudgy Penguins to NFTs minted only seconds ago!
So, what can you do with the NFT API? Here are a few examples:
- Fetch NFT Transfer Data: Fetch historical and real-time transfer data for any NFT, wallet, or address.
- Access Enriched Metadata: Access normalized and fully enriched metadata for both collections and individual NFTs.
- Get On-Chain Pricing Data: Get and integrate on-chain pricing data into your dapps, including last sale prices and lowest historical prices.
- Query Optimized Image Previews: Query and benefit from dynamically sized image previews.
The NFT API supports Solana and ten+ EVM chains, meaning you can leverage the same tool to build NFT projects across multiple blockchain networks!
Token API
With the Moralis Token API, you can effortlessly integrate real-time prices, wallet balances, and transfers into your Web3 projects. As such, when working with this tool, it has never been so easy to build decentralized exchanges (DEXs), Web3 wallets, portfolio trackers, or any other dapps!
So, what are the features of the Token API? Let’s look at a few examples:
- Get Token Prices: Get any token’s current and historical price from popular automated market makers (AMMs) like Uniswap and PancakeSwap.
- Track Token Transfers: Track transfers of any token in real time by contract or wallet. You can also fetch historical transfers with ease.
- Query Token Balances: Query token balances of any address at any given point in time.
- Advanced Spam Detection: Experience enhanced security with support for detecting suspicious tokens.
- Rich Metadata: Access up-to-date token metadata, including token names, logos, symbols, and much more.
Also, just like the NFT API, the Token API also features cross-chain support. Consequently, when using Moralis’ Token API, you can build projects compatible with Solana and all major EVM blockchains!
Wallet API
The Moralis Wallet API boasts an array of powerful features, unparalleled scalability, and exceptional flexibility, making it the ultimate tool for integrating wallet functionality into dapps. The Wallet API supports over 500 million addresses across all major blockchains, including Solana, Ethereum, Polygon, and many other EVM-compatible networks!
So, what does the Moralis Wallet API do?
- Native Balances: Access both historical and current native balances for all wallets.
- Portfolios: Fetch the entire portfolio of any wallet, including fungible and non-fungible tokens.
- NFTs: Get all NFTs and collections held by a wallet, along with metadata and images.
- Transfers: Get real-time transfers and swaps for both NFTs and fungible tokens.
- Labels: All transfer and transaction endpoints support public address labels, allowing you to easily decode transactions.
- And more!
Thanks to the cross-chain compatibility of the Wallet API, you can use this interface to build on both Solana and all major EVM chains!
Additional EVM APIs
In addition to the three APIs from the previous section, Moralis also offers numerous other EVM-compatible interfaces. And in this section, we’ll introduce you to a few of them:
- Price API: The Price API is the industry’s premier interface for crypto prices. You can pick any metric – whether you want to judge by speed, features, or pricing – this API comes out on top compared to any competitor.
- Blockchain API: The Blockchain API is the industry’s most precise and scalable interface for raw and decoded blockchain data. With single lines of code, you can seamlessly query block data, transactions, internal transactions, logs, and more.
- Streams API: With the Streams API, you can effortlessly set up streams to receive instant, customizable notifications whenever something important happens on-chain. This allows you to seamlessly monitor any user’s real-time transfers, notify your dapp users about important events, and much more.
- Market Data API: With the Market Data API, you can unlock the power of Web3 market data and seamlessly integrate this into your dapps. Query trending NFT collection, NFT drops, top ERC-20 tokens, and much more with only single lines of code.
The APIs above are only a few examples. So, if you want to explore all of them, check out our Web3 API page!
Tutorial: How to Build with Solana and EVM with Cross-Chain Compatible APIs
In this section, we’ll show you a couple of examples of how you can use our cross-chain compatible APIs to build with Moralis on both Solana and EVM blockchains. And in this case, we’ll be using the NFT API to illustrate the power of Moralis. More specifically, we’ll show you how to get the NFT balance of any address!
However, before continuing, you must deal with a few essential prerequisites!
Prerequisites
In this tutorial, we’ll be using JavaScript to get the NFT balance of any address. As such, before you continue, make sure you have the following ready:
- Node.js v14+
- NPM/Yarn
Furthermore, open your preferred integrated development environment (IDE) and set up a new project. From there, launch a new terminal, cd
into the project’s root folder and run the command below to install the Moralis SDK:
- Solana:
npm install moralis @moralisweb3/common-sol-utils
- EVM Chains:
npm install moralis @moralisweb3/common-evm-utils
Lastly, you also need a Moralis API key. As such, if you haven’t already, sign up with Moralis by clicking on the ”Start for Free” button at the top right of Moralis’ homepage:
Next, go to the ”Settings” tab, scroll down to the ”API Keys” section, and copy your key:
Keep it for now, as you need it in the coming two sections!
Nevertheless, that covers the prerequisites. In the following sections, we’ll give two examples of how you can get the NFT balance of an address on both Solana and EVM chains!
Solana Example: Get NFT Balance of an Address
Create a new ”index.js” file in your project root folder and add the following code:
const Moralis = require("moralis").default; const { SolNetwork } = require("@moralisweb3/common-sol-utils"); const runApp = async () => { await Moralis.start({ apiKey: "YOUR_API_KEY", // ...and any other configuration }); const address = "BWeBmN8zYDXgx2tnGj72cA533GZEWAVeqR9Eu29txaen"; const network = SolNetwork.MAINNET; const response = await Moralis.SolApi.account.getNFTs({ address, network, }); console.log(response.toJSON()); }; runApp();
Next, replace YOUR_API_KEY
with the key you copied in the previous section:
From there, configure the address
const by adding the address from which you want to query the NFT balance:
We then pass along address
and chain
as parameters when calling the getNFTs()
endpoint:
That’s it for the code; you can now execute the script by running the terminal command below in the project’s root folder:
node index.js
In return, you’ll get an array of all NFTs held by the address you specified. It will look something like this:
[ { "associatedTokenAddress": "B7gJmenw3xpQqq82UNHim2cFPqo5p21WY9YLf4XgVNkw", "mint": "6RPYwFcfmkzMucAGz6FrBRvDX5sK4FBqDye3iZDCw5Q", "name": "DegodsGiveaway #639", "symbol": "DG" } ]
Congratulations! You now know how to use Moralis’ NFT API to get the balance of an address on Solana! If you want to learn more about this, check out the get SPL NFT balance of address documentation page!
EVM Example: Get NFT Balance of an Address
Set up a new ”index.js” file in your project’s root folder 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 address = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; const chain = EvmChain.ETHEREUM; const response = await Moralis.EvmApi.nft.getWalletNFTs({ address, chain, }); console.log(response.toJSON()); }; runApp();
From here, swap out YOUR_API_KEY
with the key you fetched when dealing with the prerequisites:
Next, configure the address
and chain
constants to fit your query:
We then pass along address
and chain
as parameters when calling the getWalletNFTs()
endpoint:
That covers the code; you can now run the script by opening a new terminal and executing the following command in the root folder of the project:
node index.js
In return for running the script, you’ll get a response containing an array of all NFTs held by the address in question. Here’s an example of what it might look like:
{ "total": 1456, "page": 1, "page_size": 100, "cursor": "eyJhbGciOiJIUzI1NiIs//...", "result": [ { "token_address": "0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85", "token_id": "4765809967066625256798886812262830659450023020194524584471225959000376492819", "amount": "1", "owner_of": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "token_hash": "ba6d44b5f16be94283cecffeb784b7ca", "block_number_minted": "15572796", "block_number": "15573017", "contract_type": "ERC721", "name": "Ethereum Name Service", "symbol": "ENS", "token_uri": null, "metadata": null, "last_token_uri_sync": null, "last_metadata_sync": "2022-09-20T06:06:08.153Z", "minter_address": null }, ], "status": "SYNCED" }
That’s it! You now know how to use the NFT API to get the balance of an address on an EVM network! If you want to learn more about this, explore the get NFTs owned by address documentation page!
Summary: Build with Solana and EVM Compatible APIs
In today’s article, we introduced you to Moralis’ cross-chain compatible APIs – the ultimate tools allowing you to build on both Solana and EVM. In doing so, we primarily dove into the following three examples:
- NFT API
- Token API
- Wallet API
We also demonstrated the accessibility of our APIs by showing you two examples of how you can get the NFT balance of any address on both Solana and all EVM chains. As such, if you have followed along this far, you know the basics of building cross-chain compatible dapps!
If you liked this guide, consider checking out some more content here on the Web3 blog. For instance, read about meta transactions or explore our complete blockchain API tutorial.
Also, don’t forget to sign up with Moralis if you want access to all our cross-chain compatible APIs. You can create an account for free, and you’ll be able to immediately start leveraging the full power of blockchain technology!