BLOCKCHAIN SERIES

Moralis 2.0 NodeJS SDK

NodeJS SDK for web3 integration

Chikku George
BLOCK6

--

NodeJS SDK

This SDK is the first stage in the web3 integration process using Moralis with any backend.
It is modularized, simple to use, and fully supported for typescript.
The features currently offered are:
1. Connecting and making requests to the EvmAPIs and SolanaAPIs.
2. Moralis Authentication.

Install Moralis

npm i moralis

Initialize Moralis

To initialize Moralis, create an index.js file and use the start() method.
Make sure you register for Moralis and copy the API_KEY.

Credits: Author

Moralis Configuration

The following configuration options are also available for Moralis:

  1. formatEvmAddress — EVM address format style. Possible values include “lowercase” and “checksum.”
  2. formatEvmChainId — Chains’ format style. “decimal” and “hex” values are possible.
  3. logLevel — Log message detail level. Possible settings are “verbose”, “debug”, “info”, “warning”, “error” and “off”.
Credits: Author

Managing EVM Chains

The chains are not handled as decimals or hex strings by the NodeJS SDK. Rather, treats these chains as distinct class instances known as “Moralis data types.”

Install @moralisweb3/evm-utils dependency for handling EVM chains.

We can launch a fresh instance of Ethereum using either of the following methods:

const chain = EvmChain.ETHEREUM; // You need to provide chain nameOREvmChain.create(1); // You need to provide chain Id in either hex or decimal

We can access various information with the class instance we built.

Credits: Author

We may get the output as below:

Credits: Author

Managing EVM Addresses

We can create the Evm address with a lowercase or a checksum string. The address can also be formatted using the format type offered in the configuration option.

Credits: Author

We may get the output as below:

Credits: Author

Managing EVM APIs

1. Fetch Native Balance

Credits: Author

2. Fetch ERC-20 Token Balance

Credits: Author

3. Fetch NFTs with Metadata

Credits: Author

Moralis Authentication

We must use two techniques to authenticate using the SDK:

1. Moralis.Auth.requestMessage

It returns a message that must be signed by the user.

Credits: Author

2. Moralis.Auth.verify

It verifies the message signed by the user.

Credits: Author

Have a good time with the Moralis 2.0 NodeJS SDK :)

JOIN DISCORD

Contents distributed by Learn.Block6.tech

👉 Discord — Live Talks

👉 Twitter — Latest articles

👉 LinkTr.ee

--

--

Chikku George
BLOCK6
Writer for

Software Engineer | ReactJs | NodeJs | Blockchain Enthusiast