This page may contain legacy content

To get our most up-to-date content please access our documentation

October 21, 2021

Ethereum API – Develop Ethereum dApps with Moralis

Table of Contents

With blockchain technology still in its infancy, only time will tell how the future of dApps (decentralized applications) will look like on blockchains such as Ethereum. Furthermore, it’s unclear which blockchain will dominate the Web3 realm; however, Ethereum remains the current frontrunner among programmable blockchains. Therefore, building dApps on Ethereum makes a lot  of sense for blockchain developers. However, while some programmers have experienced challenges and a time-consuming process by building around RPC nodes during their development, creating dApps can be done easily and in record time when utilizing a powerful Ethereum API. As such, we’ll show how to develop Ethereum dApps and use an Ethereum API with Moralis, which will enable developers to program applications on Ethereum easily and markedly quicker.

As such, Moralis’ platform enables you to avoid reinventing the wheel and focus on the unique features of your dApps. Furthermore, in addition to providing developers with an Ethereum API, Moralis also offers an ultimate Web3 SDK that provides programmers with nodes, an entire database, and much more. On top of that, it gives you a chance to join a supportive community of blockchain developers and thus become a better blockchain developer yourself. Moralis’ Web3 development platform is the ultimate shortcut that crypto developers deserve. By shattering the outdated paradigm of building directly around Ethereum RPC nodes, Moralis enables quick deployment of dApps while saving resources. So, make sure to register your free account today and start deploying killer dApps in no time!   

Why Develop Ethereum dApps with Moralis

Ethereum was the first programmable blockchain and the one that introduced smart contracts to the world. As such, it had a head start. Thus, it was able to build an extensive and loyal community across the globe. Moreover, wherever there are strong communities, we normally see great results, and Ethereum’s success confirms that. 

Of course, this reputable chain has its limitations and issues (like other blockchains available), mainly the network’s high gas fees. However, the latter is also a good indication that there are a lot of transactions taking place on the chain, which adds to the chain’s reputation. Fortunately, by focusing on one of Ethereum’s testnets before your dApp is ready for mainnet deployment, you can partly avoid paying those fees mentioned above.

So, why develop on Ethereum? Well, a strong reputation, an extensive community, and a large pool of developers working on improving this decentralized network are all solid arguments. However, when adding the Ethereum API and Moralis’ cross-chain interoperability on the table, creating Ethereum dApps becomes a no-brainer.

If you were to create Ethereum dApps in the most common way possible, you’d immediately expose yourself to the limitations of RPC nodes. Besides wasting time and other resources, you’ll not be able to release your Web3 app quickly enough. However, when you use Moralis and all of its tools, you easily overcome all these obstacles. In the next section, you’ll see how the Ethereum API simplifies things. But before we dive deeper into the Ethereum API, let’s cover another key aspect of Web3 development.

Develop Future-Proof Ethereum dApps

As a developer, especially in a new field such as crypto, you want to create dApps that are relevant for a long time. However, since we cannot know which chain will dominate and offer the best solutions in the upcoming years, it’s important to create Web3 applications accordingly. This means that you want to be able to transfer your dApps from one chain to another effortlessly. Unfortunately, this aspect is yet another major downside of building directly on top of RPC nodes. 

On the other hand, by using Moralis to create your dApp, you get this aspect covered in the best way possible. Moralis’ cross-chain interoperability enables all your Web3 applications to be ported over to another chain easily with a few clicks. Moreover, Moralis is constantly adding full support for new reputable chains. It currently supports Binance Smart Chain (BSC), Polygon, Avalanche, and Arbitrum, with support for Solana and Elrond already in the pipeline. With that in mind, be rest assured that all of your dApps will not get stuck on one particular chain, nor will you have to start from scratch to make the transition to another chain. 

Ethereum API – Going Beyond Node Providing Services

If you’re looking to overcome the struggle of running your own node, you’ve most likely heard of blockchain node providers. While there are many reputable options on the market, Infura still caters to most Ethereum dApps. However, Infura limits you to Ethereum’s blockchain. On the other hand, Moralis gives you access to far more than merely nods – allowing you to truly develop complete Ethereum dApps.

When exploring other chains, you might have been searching for Infura for BSC or Infura for Avalanche alternatives. If so, Moralis is your answer – as it offers full support for both of these chains. Moreover, Moralis provides developers with Moralis Speedy Nodes for all supported chains; however, this is just a small portion of Moralis’ full scope. When you have Moralis’ Web3 SDK and Moralis’ Web3 API, you can cover all of your blockchain development needs.

Moralis’ support for Ethereum will speed up all your Ethereum development. This is true whether you build an NFT marketplace, crypto wallet, DeFi dashboard, cross-chain bridge, NFT game, or Ethereum DEX. All these types of decentralized applications have a lot in common. Each of them needs to log in users, fetch balances (of fungible tokens and NFTs), transactions, smart contract events, provide real-time alerts, send transactions, and they require a database. Thus, it makes sense to avoid building all these repetitive functionalities from scratch for every dApp. As such, Moralis’ Ethereum API functionality gives you powerful blockchain features by copying and pasting short snippets of code. 

Exploring the Ethereum API – The Key to Deploying dApps Fast

As mentioned, we are about to take a closer look at the Ethereum API offered by Moralis. Using this functionality to your advantage will make your future Web3 development endeavors as fast and simple as possible.

Moreover, while we talk about the Ethereum API, note that because of Moralis’ built-in cross-chain interoperability, you get to apply the same API to other supported chains. The only difference is that the Ethereum chain is the native option. As such, when working with other chains, you need to specify the chain of interest.

Most Powerful Ethereum API 

As mentioned previously, there are many functionalities that most dApps need to incorporate. Giving your users an option to log in or to authenticate themselves is one of such features. While creating these basic features takes a lot of effort when building directly on top of RPC nodes, using Moralis takes care of it with two short snippets of code:

Moralis.Web3.authenticate().then(function (user) {
    console.log(user.get('ethAddress'))
})

By using the above code, every user can authenticate with MetaMask easily. Moreover, while MetaMask remains the most popular Ethereum authentication solution, Moralis also offers WalletConnect integration. The latter is an excellent option for authenticating mobile users. 

Once users are authenticated, then they’re automatically added to your Moralis dashboard. Furthermore, they’re automatically updated in real-time to provide you with the latest on-chain state continually. As you can see from the image below, it offers you a ton of valuable on-chain data for every address used to log in.

Ethereum API for Reading Database

Once we authenticate users, important on-chain data is at our disposal. Moreover, you can count on Moralis to provide you with short single lines of code to access all sorts of on-chain information without breaking a sweat. For instance, let’s take a closer look at code snippets regarding transactions and how to get token balances

  • Getting mainnet transactions for the current user:

const transaction = await Moralis.Web3API.account.getTransaction();

  • Getting ETH balance for the current user:

const balance = await Moralis.Web3API.account.getNativeBalance();

  • Getting ERC-20 token balances for the current user on the mainnet:

const balances = await Moralis.Web3API.account.getTokenBalances();

  • Getting NFT balances for the current user on the mainnet:

const balance = await Moralis.Web3API.account.getNFTs();

The above four lines of code provide you with all the essential snippets (as far as the backend goes) to create a crypto wallet. Of course, there are a lot more options available. For instance, when it comes to NFTs, you can obtain NFTs metadata, including tokens’ URI easily. Here is what the code looks like:

const metaData = await Moralis.Web3API.token.getNFTMetadata(options);

Moreover, you can also get NFT owners:

const nftOwners = await Moralis.Web3API.token.getNFTOwners(options);

Furthermore, you can search for NFTs based on their metadata and much more. Now you can see how Moralis’ ultimate NFT API makes implementing NFTs in your dApps pretty simple.

In addition, you can run any “MongoDB” query on your Moralis database, which offers you a vast array of options. Moreover, you also get real-time alerts through sockets quite easily.

Ethereum API for Sending Assets

When building any Web3 application, it’s also important to enable users to send their assets. Of course, you can again count on the Ethereum API to provide you with simple solutions:

  • Sending ETH:
// sending 0.5 ETH
const options = {type: "native", amount: Moralis.Units.ETH("0.5"), receiver: "0x.."}
let result = await Moralis.transfer(options)
  • Transfering ERC-20:
// sending 0.5 tokens with 18 decimals
const options = {type: "erc20", 
                 amount: Moralis.Units.Token("0.5", "18"), 
                 receiver: "0x..",
                 contractAddress: "0x.."}
let result = await Moralis.transfer(options)
  • Sending NFTs:
// sending a token with token id = 1
const options = {type: "erc721",  
                 receiver: "0x..",
                 contractAddress: "0x..",
                 tokenId: 1}
let result = await Moralis.transfer(options)

// sending 15 tokens with token id = 1
const options = {type: "erc1155",  
                 receiver: "0x..",
                 contractAddress: "0x..",
                 tokenId: 1,
                 amount: 15}
let result = await Moralis.transfer(options)

If you want to explore the Ethereum API further, we recommend checking out Moralis’ documentation. Moreover, we encourage you to take on some of our example projects (learn to create Ethereum tokens in four steps, build an NFT game app, create NFTs, etc.). That way, you’ll get to actually use the Ethereum API and thus experience its full power first-hand, which is the best way to learn using this excellent tool properly. 

Ethereum API – Develop Ethereum dApps with Moralis – Summary 

Running your own RPC node and building the infrastructure around it is not optimal when creating dApps in 2021. This outdated way of Web3 programming is quite limiting and consumes a lot of time and other resources. Furthermore, it makes keeping your dApp up to date extremely challenging. However, we’ve shown you how simple dApp development can be when using a high-quality Ethereum API. It takes the heavy lifting off of your shoulders since it covers most of the backend coding by enabling you to copy and paste single lines of code. That way, you can devote your attention and resources towards creating the best possible user experience on the frontend.

At this point, you should have a rather clear understanding of how Moralis’ Ethereum API can make your dApp development a lot simpler and quicker. This ultimate Web3 operating system for building cross-chain compatible dApps offers full support for Ethereum and other leading programmable blockchains. As such, it provides you with a future-proof guarantee since you can simply transfer your dApps among different chains. All-in-all, Moralis’ SDK and other Moralis features provide the ultimate Ethereum API and an excellent platform to develop Ethereum dApps quickly and easily.

If you found the information herein useful and would like to level up your development skills, make sure to enroll in the “Ethereum 101” course from Ivan on Tech Academy. In that course, you’ll dive deeper into the world of Ethereum, and you’ll have a greater knowledge of how Ethereum and smart contracts work. Moreover, it will advance and future-proof your blockchain career. 

In addition, visit Moralis’ blog and Moralis’ YouTube channel for more in-depth explanations of various blockchain topics. Even if you want to branch outside Ethereum, perhaps into BSC programming and BEP20 tokens, we’ve got the right tools!

Market Data API
Build amazing trading and portfolio dapps with this Market Data API. Keep users engaged with up-to-date data!
Market Data API
Related Articles
October 18, 2023

How to Set Custom Webhooks with Moralis Streams

September 27, 2023

What is an Ethereum Node and How to Set One Up

November 22, 2023

Best NFT Data Analytics for 2024 – Real-Time NFT Transfers, Tracking & Discovery

April 10, 2024

How to Get All Owners of an ERC20 Token 

November 9, 2022

Solana Smart Contract Examples for Developers

August 31, 2022

Fastest Way to Build a Web3 App

November 17, 2022

Exploring the Optimism Network – A Next-Gen L2 Blockchain for Ethereum

February 20, 2023

Oasis Testnet Faucet – Get Testnet Funds for the Oasis Network

December 15, 2022

Ultimate Web3 Py Tutorial for Blockchain Developers