Saturday, June 20, 2026
No Result
View All Result
Crypeto News
  • Home
  • Bitcoin
  • Crypto Updates
    • General
    • Blockchain
    • Ethereum
    • Altcoin
    • Mining
    • Crypto Exchanges
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Analysis
  • Regulations
  • Scam Alert
  • Videos
CRYPTO MARKETCAP
  • Home
  • Bitcoin
  • Crypto Updates
    • General
    • Blockchain
    • Ethereum
    • Altcoin
    • Mining
    • Crypto Exchanges
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Analysis
  • Regulations
  • Scam Alert
  • Videos
CRYPTO MARKETCAP
Crypeto News
No Result
View All Result

Develop and Launch Dapps Quickly In This NodeJS Web3 Tutorial

by crypetonews
October 15, 2022
in Web3
Reading Time: 12 mins read
0 0
A A
0
Home Web3
Share on FacebookShare on Twitter


Do you want to create a decentralized application but are overwhelmed with the Web3 tech stack? If so, this NodeJS Web3 tutorial can help you get started as it presents the easiest way to build dapps. Furthermore, in this article, you have the chance to follow along as we take on a NodeJS Web3 example that will teach you the basics, and you’ll explore the essential tools and how to use them. As a result, you’ll know how to fetch on-chain data, which will be effortless thanks to Moralis’ enterprise-grade Web3 APIs. Moreover, we decided to make this tutorial as beginner-friendly as possible. Thus, you’ll be able to complete today’s NodeJS Web3 example by simply copying our code. 

In addition, we’ll show you how to obtain your Moralis Web3 API key. The latter will give you access to the ultimate Web3 API – your gateway to developing dapps (decentralized applications). With the power of Moralis by your side, you’ll get to contribute to Web3 with NodeJS without breaking a sweat. 

Additionally, since Moralis is all about cross-chain interoperability, you’ll get to use today’s NodeJS Web3 tutorial to tackle various blockchains. Hence, you can stick to the leading programmable chain, Ethereum, or focus on other reputable EVM-compatible chains. In either case, you must first create your free Moralis account. However, before diving deeper into our main topic, let’s ensure you all know the basics. 

What is NodeJS?

NodeJS, also Node.js, is a programming platform or environment. It was launched back in 2009, with its primary purpose to help devs manage some of the complexities of JavaScript (JS). Moreover, Web3 with NodeJS expands the possibilities for dapp development. Also, NodeJS was built on Chrome’s JavaScript runtime, making it easier for developers to build scalable, high-performance apps. Ultimately, here are NodeJS’s core characteristics:

Event-Driven, Non-Blocking I/O Model – NodeJS utilizes an event-driven, non-blockchain I/O model. This prevents the node process from locking up the entire web application when retrieving a sole response. Instead, it simply continually runs and moves on to the next event until the event queue is empty. Moreover, NodeJS uses a unique event model. This model, besides a library, also uses an event loop as a runtime constructor. That event model can start an event loop without a “blocking call”. Thanks to these features, NodeJS is lightweight, efficient, and suitable for real-time applications across decentralized networks.Client-Side and Server-Side – NodeJS is able to run on the client-side (frontend) and server-side (backend). Accordingly, it enhances the use of JavaScript. Thanks to these real-time, two-way connections of web applications, both the server and client can initiate communications and freely exchange data.Reuse Code – NodeJS enables developers to reuse code. This is where the NodeJS packing manager (NPM) enters the scene. Also, developers can complete their programming tasks with over a million packages. Furthermore, developers who run JavaScript-heavy applications particularly benefit from reusing code. That way, they avoid the added burden of context-switching between edit and search tools.

Green background with NodeJS letters.

Nonetheless, proper support for real-time data exchange and communication is essential when dealing with public blockchains, which is exactly what NodeJS supports.

Outlining the main advantages of NodeJS: load time, easy to learn, high level of performance, better app response time, and real-time data.

Why Use a NodeJS Web3 Example from Moralis?

The above image shows the main advantages of NodeJS for developers and users. These key benefits are compelling as they address some important aspects of creating web applications. The majority of these pros come from the core NodeJS characteristics presented in the previous section. Hence, when exploring NodeJS, it’s definitely worth learning how to use NodeJS the easy way. This is where the Moralis NodeJS Web3 tutorial enters the scene. In today’s example, you will learn to dive into Web3 with NodeJS and learn about Moralis and its powerful API. Consequently, you’ll be able to use the tools that this API provider offers to take your Web3 development game to the next level.

With that said, make sure to roll up your sleeves and follow our lead.

Billboard on computer stating "Web3 Tutorial".

Create a Dapp for Web3 with NodeJS – NodeJS Web3 Tutorial

If you decide to follow our lead as we take on today’s NodeJS Web3 tutorial, you’ll learn to complete the following five steps:

Create a NodeJS ApplicationImport and Set Up the Latest Moralis JS SDKSet Up a Simple Express ServerIntegrate Your App with Moralis ServicesFetch Blockchain Data  

As you can see, there’s quite a lot of ground to cover. Thus, let’s dive right into the first step. But before moving any further, make sure you have Visual Studio Code installed and set up, NodeJS installed, and your free Moralis account ready. These are also the three prerequisites to today’s quest. Next, launch your VSC terminal and follow our lead:

An arrow pointing to the "terminal button in VSC to a "NodeJS Web3 Tutorial" user.

Create a NodeJS Application

We’ll first create a new folder and open it in Visual Studio Code (VSC). We’ll name our folder “Simple-NodeJS”. Then, we use our terminal and enter the “npm init” command. Next, we name our project and stick to the default options by pressing enter a few times. By doing so, we end up with a new “package.json” file that includes the following lines of code:

{
“name”: “simple-nodejs-demo”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“test”: “echo \”Error: no test specified\” && exit 1″
},
“author”: “”,
“license”: “ISC”
}

Import and Set Up the Latest Moralis JS SDK

When it comes to importing and setting up the latest Moralis JS SDK, we only need to execute a single command. Essentially, we just need to install the “moralis” dependency. However, we can use a single command to also install the “express” dependency. So, we proceed by entering the “npm install moralis express” command in our terminal.

npm install moralis express

Computer screen with various code and the ExpressJS statement on top.

Set Up a Simple Express Server

By entering the above command, we already have the “express” dependency installed. Hence, we can proceed with setting up a simple Express server. Create the “index.js” file and use the following lines of code:

const express = require(‘express’)
const app = express()
const port = 3000
app.get(‘/’, (req, res) => {
res.send(‘Hello World!’)
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})

We must also revisit the “package.json” file and add the “start” script:

“scripts”: {
“start”: “node index.js”
},

Now that our “index.js” file is ready and we’ve set the “start” script in place, we can run our Express server. Again, a simple command – “npm run start” – is all we need. Then, we can use our favorite browser to visit “http://localhost:3000″ and make sure it displays the “Hello World!” greeting.

A wizard pointing towards Moralis.

Integrate Your App with Moralis Services 

With the first three steps of our NodeJS Web3 tutorial under our belts, it’s time we focus on integrating our app with Moralis services. In order to complete this step, we’ll use the above-created “index.js” file. This is where we’ll paste in our Moralis Web3 API key. However, we must first import Moralis and the “EvmChain” data type:

// Import Moralis
const Moralis = require(‘moralis’).default
// Import the EvmChain dataType
const { EvmChain } = require(“@moralisweb3/evm-utils”)
Then, we add the “MORALIS_API_KEY”, “address”, and “chain” variables:
// Add a variable for the API key, address, and chain
const MORALIS_API_KEY = “replace_me”
const address = “replace_me”
const chain = EvmChain.ETHEREUM

As you can see above, we need to replace the “replace me” placeholder with our actual API key. We’ll do that in a bit, but let’s also point out that we decided to focus on the Ethereum chain. However, we could’ve easily focused on any other EVM-compatible chain Moralis supports:

Ethereum Testnets:ROPSTENRINKEBYGOERLIKOVANSEPOLIAPOLYGONMUMBAIBSCBSC_TESTNETAVALANCHEFUJIFANTOMCRONOSCRONOS_TESTNET

Before we obtain our Moralis Web3 API key, we also need to initialize Moralis with the following lines of code:

const startServer = async () => {
await Moralis.start({
apiKey: MORALIS_API_KEY,
})

Moralis Web3 API Key – How to Get It?

To get the Moralis Web3 API key, log in to your Moralis account. Once inside our admin area, you must go to the “Web3 APIs” page. There, use the copy icon to copy the API key. Basically, obtaining your Moralis Web3 API key is a simple two-step process:

Showing 2-step process, clicking on Web3 APIs, and copying the API key.

Of course, we must return to our “index.js” file and paste the above-copied key next to the “apiKey” variable. Ultimately, this is the content of our “index.js” file so far: 

const express = require(‘express’)

// Import Moralis
const Moralis = require(‘moralis’).default

// Import the EvmChain dataType

const { EvmChain } = require(“@moralisweb3/evm-utils”)
const app = express()
const port = 3000

// Add a variable for the api key, address and chain

const MORALIS_API_KEY = “replace_me”
const address = “replace_me”
const chain = EvmChain.ETHEREUM
app.get(‘/’, (req, res) => {
res.send(‘Hello World!’)
})

// Add this a startServer function that initializes Moralis

const startServer = async () => {
await Moralis.start({
apiKey: MORALIS_API_KEY,
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
}

// Call startServer()

startServer()

Fetch Blockchain Data – Web3 with NodeJS Examples

Now that we’ve completed the above four steps, it’s time we explore Web3 with NodeJS. This is the part of today’s NodeJS Web3 tutorial where you’ll learn how to fetch native balance, ERC-20 balance, and NFTs. Fortunately, the Moralis API offers powerful and practical endpoints for each of these blockchain pieces of information. So, let’s look at three powerful examples of fetching on-chain data.

Physical Ethereum asset on a desk.

Fetch Native Balance

When it comes to fetching the native balance, which in our case is the Ethereum balance, we can use Moralis’ “getNativeBalance” endpoint. To use this endpoint in our “index.js” file, we’ll create the “getDemoData” function:

async function getDemoData() {
// Get native balance
const nativeBalance = await Moralis.EvmApi.balance.getNativeBalance({
address,
chain,
})
// Format the native balance formatted in ether via the .ether getter
const native = nativeBalance.result.balance.ether
return { native }
}

Looking at the above lines of code, you can also see that we are using “.ether” to display the native balance in the proper format. 

Note: You can explore the entire array of Moralis’ EVM API endpoints in the Moralis documentation.

In addition, for our dapp to properly return the results of the above “getDemoData” function, we must also add the “/crypto-data” endpoint:

app.get(“/demo”, async (req, res) => {
try {
// Get and return the crypto data
const data = await getDemoData()
res.status(200)
res.json(data)
} catch (error) {
// Handle errors
console.error(error)
res.status(500)
res.json({ error: error.message })
}
})

Essentially, the lines of code above enable us to call the “/crypto-data” endpoint using the “http://localhost:3000/demo” address. This call returns the native balance in the following format:

{
“native”: “0.169421625822962794”
}

An ERC-20 coin on top of a dollar bill.

Fetch ERC-20 Balance

When it comes to fetching ERC-20 balances, things follow the native balance’s lead. As such, we need to complete steps similar to the ones above. However, this time we focus on using the “getWalletTokenBalances” endpoint from the “token” API group:

// Get token balances
const tokenBalances = await Moralis.EvmApi.token.getWalletTokenBalances({
address,
chain,
})
// Format the balances to a readable output with the .display() method
const tokens = tokenBalances.result.map((token) => token.display())
// Add tokens to the output
return { native, tokens }
}

Looking at the lines of codes above, you can see that we again ensure the balances are displayed properly. We also added “tokens” to our “return” parameter.

NFT art collected as an artpiece.

Fetch NFTs

Finally, we will complete the last stage of our NodeJS Web3 example – fetching NFTs. To do this successfully, we’ll yet again implement similar lines of code as for the native and ERC-20 balances. This time, we will use the “getWalletNFTs” endpoint from the “nft” API group. Furthermore, we will focus on fetching the first ten NFTs for a given address. Of course, we will do this with our “getDemoData” function. In addition, we also need to format the output properly. Nonetheless, we must not forget to add “nfts” to “return“:

// Get the nfts
const nftsBalances = await Moralis.EvmApi.nft.getWalletNFTs({
address,
chain,
limit: 10,
})
// Format the output to return name, amount and metadata
const nfts = nftsBalances.result.map((nft) => ({
name: nft.result.name,
amount: nft.result.amount,
metadata: nft.result.metadata,
}))
// Add nfts to the output
return { native, tokens, nfts }
}

NodeJS Web3 Tutorial – The “index.js” Example File

At this point, we have successfully implemented successful fetching of the native balance, ERC-20 balance, and NFTs in our NodeJS dapp. Consequently, we’ve finished our NodeJS Web3 tutorial. However, to assist you even further and help you avoid making any mistakes while putting the above lines of code together, you can find the entire code below. Simply copy and paste it into VSC. Also, remember to replace “replace_me” with the “MORALIS_API_KEY” variable. Nonetheless, if you want to explore other blockchains, replace “ETHEREUM” with one of the other supported chains as listed in the “Integrate Your App with Moralis Services” section above. 

So, here’s the entire code for the “index.js” file:

const express = require(“express”)
const Moralis = require(“moralis”).default
const { EvmChain } = require(“@moralisweb3/evm-utils”)

const app = express()
const port = 3000

const MORALIS_API_KEY = “replace_me”
const address = “0x9e8f0f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f”
const chain = EvmChain.ETHEREUM

async function getDemoData() {
// Get native balance
const nativeBalance = await Moralis.EvmApi.balance.getNativeBalance({
address,
chain,
})

// Format the native balance formatted in ether via the .ether getter
const native = nativeBalance.result.balance.ether

// Get token balances
const tokenBalances = await Moralis.EvmApi.token.getWalletTokenBalances({
address,
chain,
})

// Format the balances to a readable output with the .display() method
const tokens = tokenBalances.result.map((token) => token.display())

// Get the nfts
const nftsBalances = await Moralis.EvmApi.nft.getWalletNFTs({
address,
chain,
limit: 10,
})

// Format the output to return name, amount and metadata
const nfts = nftsBalances.result.map((nft) => ({
name: nft.result.name,
amount: nft.result.amount,
metadata: nft.result.metadata,
}))

return { native, tokens, nfts }
}

app.get(“/demo”, async (req, res) => {
try {

// Get and return the crypto data
const data = await getDemoData()
res.status(200)
res.json(data)
} catch (error) {
// Handle errors
console.error(error)
res.status(500)
res.json({ error: error.message })
}
})

const startServer = async () => {
await Moralis.start({
apiKey: MORALIS_API_KEY,
})

app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
}

startServer()

NodeJS Web3 Tutorial – Create Dapps Using a NodeJS Web3 Example – Summary

Today’s guide was all about using NodeJS for Web3 development. As such, you had a chance to follow our NodeJS Web3 tutorial and create your own backend dapp. You also learned how to set Moralis’ Web3 functionalities in place and how to make Web3 API calls to fetch all sorts of on-chain data. As a result, you are now ready to take your dapp development further. For instance, you can take the above backend and simply link it to a React or NextJS app. On the other hand, you may take an even faster path by simply using our ultimate Web3 website template.

We encourage you to level up your Web3 development skills by taking on tutorials that await you in the Moralis documentation, the Moralis YouTube channel, and the Moralis blog. These outlets can help you become a blockchain developer for free. For instance, some of the latest topics show you how to connect dapps to Cronos, build BNB Chain dapps, set up and connect a dapp to the Ethereum network, connect a dapp to Polygon, clone Zapper, how to integrate blockchain-based authentication, set up a self-hosted Parse Server, and much more.  

You may also want to explore professional blockchain development courses at Moralis Academy. For instance, you can enroll in a course that will teach you how to build a DEX (decentralized exchange) using JavaScript. Nonetheless, by completing the courses at Moralis Academy, you become blockchain certified. In turn, you greatly improve your chances of landing your crypto dream job. Enroll in Moralis Academy today, and take your first steps toward a life-changing career!

A diploma showing a certificate for completing the NodeJS Web3 tutorial.



Source link

Tags: dAppsDeveloplaunchNodeJSQuicklyTutorialWeb3
Previous Post

Crypto and NFT Market News

Next Post

IT'S OFFICIAL!!! THE UFC WILL BE IN THE METAVERSE!! + UFC 280 NEWS & UFC VEGAS 62 PREDICTIONS!

Related Posts

Ronin API – Build on Ronin with Moralis
Web3

Ronin API – Build on Ronin with Moralis

May 28, 2025
How to Build NFT Apps on Solana
Web3

How to Build NFT Apps on Solana

May 23, 2025
Solana NFT API – Exploring the Top 2025 NFT API for Solana
Web3

Solana NFT API – Exploring the Top 2025 NFT API for Solana

May 21, 2025
Get Solana Whales – How to Fetch Top Whales of a Solana Token
Web3

Get Solana Whales – How to Fetch Top Whales of a Solana Token

May 19, 2025
Neobank App Development – How to Build a Web3 Neobank
Web3

Neobank App Development – How to Build a Web3 Neobank

May 16, 2025
How to Get Top Solana Token Holders
Web3

How to Get Top Solana Token Holders

May 14, 2025
Next Post
IT'S OFFICIAL!!! THE UFC WILL BE IN THE METAVERSE!! + UFC 280 NEWS & UFC VEGAS 62 PREDICTIONS!

IT'S OFFICIAL!!! THE UFC WILL BE IN THE METAVERSE!! + UFC 280 NEWS & UFC VEGAS 62 PREDICTIONS!

Brian Armstrong Will Sell 2% Of His Coinbase Holdings To Fund Scientific Research

Brian Armstrong Will Sell 2% Of His Coinbase Holdings To Fund Scientific Research

Leave a Reply Cancel reply

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

RECOMMENDED

No Content Available

  • USD
  • EUR
  • GBP
  • AUD
  • JPY
  • bitcoinBitcoin(BTC)
    $63,307.000.72%
  • ethereumEthereum(ETH)
    $1,704.270.05%
  • tetherTether(USDT)
    $1.000.02%
  • binancecoinBNB(BNB)
    $579.99-0.28%
  • usd-coinUSDC(USDC)
    $1.000.01%
  • rippleXRP(XRP)
    $1.14-0.85%
  • solanaSolana(SOL)
    $69.640.12%
  • tronTRON(TRX)
    $0.3224400.47%
  • Figure HelocFigure Heloc(FIGR_HELOC)
    $1.032.13%
  • HyperliquidHyperliquid(HYPE)
    $68.600.80%
  • Trending
  • Comments
  • Latest
4 Expert Tips to Turn Blank Pages Into Business Blueprints

4 Expert Tips to Turn Blank Pages Into Business Blueprints

October 21, 2024
Top Crypto Portfolio Rebalancing Tools (Automated & Manual)

Top Crypto Portfolio Rebalancing Tools (Automated & Manual)

April 13, 2025
What are Meta Transactions? Exploring ERC-2771

What are Meta Transactions? Exploring ERC-2771

October 25, 2023
How to Set Up NFT Sales Notifications

How to Set Up NFT Sales Notifications

October 19, 2023
Uniswap v4 Teases Major Updates for 2025

Uniswap v4 Teases Major Updates for 2025

January 2, 2025
A 98% Crash and a Pump & Dump

A 98% Crash and a Pump & Dump

August 8, 2025
AI Expert: Truth Protocols Could Become the SSL of the Information Age

AI Expert: Truth Protocols Could Become the SSL of the Information Age

August 24, 2025
Analyst Says Dogecoin Price Is Entering Expansion Phase, Here’s What It Means

Analyst Says Dogecoin Price Is Entering Expansion Phase, Here’s What It Means

August 24, 2025
Robert Kiyosaki Exposes Brutal Truth Behind Sudden Wealth and Collapse

Robert Kiyosaki Exposes Brutal Truth Behind Sudden Wealth and Collapse

August 24, 2025
Ethereum’s Tech Edge Could Outshine Bitcoin — Here’s How

Ethereum’s Tech Edge Could Outshine Bitcoin — Here’s How

August 23, 2025
IRS Loses Top Crypto Enforcer After Only 90 Days on the Job

IRS Loses Top Crypto Enforcer After Only 90 Days on the Job

August 23, 2025
US Court Grants Stay In Coinbase Biometric Data Lawsuit — Details

US Court Grants Stay In Coinbase Biometric Data Lawsuit — Details

August 23, 2025
Crypeto News

Find the latest Bitcoin, Ethereum, blockchain, crypto, Business, Fintech News, interviews, and price analysis at Crypeto News.

CATEGORIES

  • Altcoin
  • Analysis
  • Bitcoin
  • Blockchain
  • Crypto Exchanges
  • Crypto Updates
  • DeFi
  • Ethereum
  • Metaverse
  • Mining
  • NFT
  • Regulations
  • Scam Alert
  • Uncategorized
  • Videos
  • Web3

LATEST UPDATES

  • AI Expert: Truth Protocols Could Become the SSL of the Information Age
  • Analyst Says Dogecoin Price Is Entering Expansion Phase, Here’s What It Means
  • Robert Kiyosaki Exposes Brutal Truth Behind Sudden Wealth and Collapse
  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us
  • About Us

Copyright © 2022 Crypeto News.
Crypeto News is not responsible for the content of external sites.

No Result
View All Result
  • Home
  • Bitcoin
  • Crypto Updates
    • General
    • Blockchain
    • Ethereum
    • Altcoin
    • Mining
    • Crypto Exchanges
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Analysis
  • Regulations
  • Scam Alert
  • Videos

Copyright © 2022 Crypeto News.
Crypeto News is not responsible for the content of external sites.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In