Home

Awesome

<!-- CAUTION: This file is automatically generated. Do not edit it manually! To adjust it, change the sdk-readme code generator or its template --> <div align="center"> <a align="center" href="https://moralis.io" target="_blank"> <img src="https://github.com/MoralisWeb3/Moralis-JS-SDK/raw/main/assets/moralis-logo.svg" alt="Moralis JS SDK" height=200/> </a> <h1 align="center">Moralis SDK (JavaScript / TypeScript)</h1> <a href="https://discord.gg/moralis" target="_blank"> <img alt="Join the Moralis DAO on Discord" src="https://img.shields.io/discord/819584798443569182?color=7289DA&label=Discord&logo=discord&logoColor=ffffff"> </a> <a href="https://docs.moralis.io" target="_blank"> <img alt="Check the docs" src="https://img.shields.io/badge/Docs-Full Documentation-21BF96?style=flat&logo=gitbook&logoColor=ffffff"> </a> <a href="https://forum.moralis.io" target="_blank"> <img alt="Discourse posts" src="https://img.shields.io/discourse/posts?color=B7E803&label=Forum&logo=discourse&server=https%3A%2F%2Fforum.moralis.io"> </a><br/> <a href="https://www.npmjs.com/package/moralis"><img alt="npm" src="https://img.shields.io/npm/v/moralis?label=version"></a> <img src="https://img.shields.io/github/last-commit/MoralisWeb3/Moralis-JS-SDK"> <img src="https://img.shields.io/bundlephobia/minzip/moralis"> <img src="https://img.shields.io/npm/types/moralis"> <p> </p> <p> The most powerful Web3 library for your backend in Javascript and Typescript. </p> <br/> </div>

Features:

... and much more. Check the official Moralis docs for more details.

🚀 Quick start

If you're new to Moralis, check the quickstart guide in the official docs on how to get started.

If you're already familiar with Moralis and have your server set up. Then follow along to connect your SDK:

1. Install Moralis

The easiest way to integrate the Moralis SDK into your JavaScript project is through the npm module.

Install the package via npm:

npm install moralis

or yarn:

yarn add moralis

Import Moralis:

import Moralis from 'moralis';

2. Initialize Moralis

After your dependency is added, you simply need to initialize moralis via the start method:

⚠️ Warning: Make sure to keep your api key private

Moralis.start({
  apiKey: 'YOUR_API_KEY',
});

After that you can use any Moralis functionalities as described in our extensive docs

⭐️ Star us

If this JS SDK helps you build your dapps faster - please star this project, every star makes us very happy!

🤝 Need help

If you need help with setting up the boilerplate or have other questions - don't hesitate to write in our community forum and we will check asap. Forum link. The best thing about this SDK is the super active community ready to help at any time! We help each other.

🧭 Table of Contents

⚙️ Configuration

When calling Moralis.start, you can include a configuration object.

👩‍🔬 Advanced setup

It's possible to install all functionalities of Moralis by installing moralis as a dependency. But, you may choose to only install certain modules (as listed below).

1. Install the dependencies

Instead of installing moralis you can need to install the packages that you want to use. You always need to install the @moralisweb3/common-core package. For example:

yarn add @moralisweb3/common-core @moralisweb3/evm-api

Then at the top of your code (before any interaction with Moralis), you need to register the modules to the core package

import { Core } from '@moralisweb3/common-core';
import { EvmApi } from '@moralisweb3/evm-api';

const core = Core.create();
// Register all imported modules to the @moralisweb3/common-core module
core.registerModules([EvmApi]);

Then, initialize the app the same way as when using the umbrella moralis package. You only need to provide configuration that is required by the packages. So if you don't include an api package, then you might not need to include the apiKey.

core.start({
  apiKey: 'YOUR_API_KEY',
  // ...and any other configuration
});

Now you can use any functionality from the installed modules. The only difference is that you need to call in your code:

import { EvmApi } from '@moralisweb3/evm-api';

const evmApi = core.getModule<EvmApi>(EvmApi.moduleName);
evmApi.block.getBlock();

Instead of

import Moralis from 'moralis';

Moralis.EvmApi.block.getBlock();

Of course you are free to combine the modules in a single object, and use that in your dapp.

// moralis.ts
import { Core } from '@moralisweb3/common-core';
import { EvmApi } from '@moralisweb3/evm-api';

const core = Core.create();
const evmApi = EvmApi.create(core);
core.registerModules([evmApi]);

export const Moralis = {
  EvmApi: evmApi,
};

// app.ts
import { Moralis } from './moralis/';

Moralis.EvmApi.block.getBlock();

📦 Packages

Main modules

The main modules of the SDK

packagechangelogdescription
moralisCHANGELOG.mdThe main package of Moralis containing all features. You probably are looking for this one.

Integrations

Integrations with frameworks and services

packagechangelogdescription
@moralisweb3/nextCHANGELOG.mdIntegration of Moralis in NextJs
@moralisweb3/parse-serverCHANGELOG.mdIntegration of Moralis in parse-server

Features

Feature modules. Only use these directly for advanced use-cases, the prefered way is to use these features via the umbrella package "moralis"

packagechangelogdescription
@moralisweb3/authCHANGELOG.mdAuthenticate via web3
@moralisweb3/evm-apiCHANGELOG.mdMake calls to the Evm blockchain via Moralis Evm Apis
@moralisweb3/sol-apiCHANGELOG.mdMake calls to the Solana blockchain via Moralis Solana Apis
@moralisweb3/streamsCHANGELOG.mdSubscribe to realtime data from the blockchain

Core modules

Core modules are the building blocks of Moralis.

packagechangelogdescription
@moralisweb3/common-coreCHANGELOG.mdAll core logic related to the SDK

Utilities

Utilities, types, operations and datatypes related used by other modules.

packagechangelogdescription
@moralisweb3/api-utilsCHANGELOG.mdUtilities and types to handle logic for api calls
@moralisweb3/client-api-utilsCHANGELOG.mdClient-side utilities for api calls
@moralisweb3/client-evm-apiCHANGELOG.mdClient-side logic for making Evm Api calls
@moralisweb3/client-sol-apiCHANGELOG.mdClient-side logic for making Solana Api calls
@moralisweb3/common-aptos-utilsCHANGELOG.mdUtilities, operations, datatypes and types related to Aptos
@moralisweb3/common-auth-utilsCHANGELOG.mdUtilities, operations, datatypes, and types related to Auth
@moralisweb3/common-evm-utilsCHANGELOG.mdUtilities, operations, datatypes and types related to Evm
@moralisweb3/common-sol-utilsCHANGELOG.mdUtilities, operations, datatypes and types related to Solana
@moralisweb3/common-streams-utilsCHANGELOG.mdUtilities, operations, datatypes and types related to Streams

Tools

Stand-alone tools and utilities

packagechangelogdescription
@moralisweb3/eslint-configCHANGELOG.mdEslint rules, used within the Moralis SDK and its demo projects

🧙‍♂️ Community