BLOCKCHAIN SERIES
Moralis 2.0 NodeJS SDK
NodeJS SDK for web3 integration
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.
Moralis Configuration
The following configuration options are also available for Moralis:
- formatEvmAddress — EVM address format style. Possible values include “lowercase” and “checksum.”
- formatEvmChainId — Chains’ format style. “decimal” and “hex” values are possible.
- logLevel — Log message detail level. Possible settings are “verbose”, “debug”, “info”, “warning”, “error” and “off”.
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.
We may get the output as below:
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.
We may get the output as below:
Managing EVM APIs
1. Fetch Native Balance
2. Fetch ERC-20 Token Balance
3. Fetch NFTs with Metadata
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.
2. Moralis.Auth.verify
It verifies the message signed by the user.
Have a good time with the Moralis 2.0 NodeJS SDK :)
Contents distributed by Learn.Block6.tech
👉 Discord — Live Talks
👉 Twitter — Latest articles