Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

moralis-v1

MoralisWeb33.7kBSD-3-Clause1.13.0TypeScript support: included

The Moralis JavaScript SDK

cloud, mobile, api

readme

Note: This is the v1 version of the Moralis JS SDK, to support bugfixes. For the latest version, see https://github.com/MoralisWeb3/Moralis-JS-SDK

Moralis Build Serverless web3 apps

Moralis SDK for JavaScript

A library that gives you access to the powerful Moralis Server backend from your JavaScript app.

For more information on Moralis and its features, see the website, the JavaScript guide, the Cloud Code guide or Web3 Reference.

Getting Started

The easiest way to integrate the Moralis SDK into your JavaScript project is through the npm module. However, if you want to use a pre-compiled file, you can fetch it from unpkg. The development version is available at https://unpkg.com/moralis-v1/dist/moralis.js, and the minified production version is at https://unpkg.com/moralis-v1/dist/moralis.min.js.

Webpack v5 support

There are a lot of breaking changes in Webpack v5. Set up your project to work with Moralis JS SDK:

configuring Webpack v5

We highly recommend you to use the stable 4.0.3 version of Webpack. If you want to use Moralis on your project with Webpack v5 you need to add the fallback to your webpack.config.js file:

module.exports = {
    resolve: {
        fallback: {
            assert: require.resolve('assert'),
            crypto: require.resolve('crypto-browserify'),
            http: require.resolve('stream-http'),
            https: require.resolve('https-browserify'),
            os: require.resolve('os-browserify/browser'),
            stream: require.resolve('stream-browserify'),
        },
    },
};

Using Moralis on Different Platforms

The JavaScript ecosystem is wide and incorporates a large number of platforms and execution environments. To handle this, the Moralis npm module contains special versions of the SDK tailored to use in Node.js and React Native environments. Not all features make sense in all environments, so using the appropriate package will ensure that items like local storage, user sessions, and HTTP requests use appropriate dependencies. For server side rendered applications, you may set the SERVER_RENDERING variable to prevent warnings at runtime.

To use the npm modules for a browser based application, include it as you normally would:

const Moralis = require('moralis-v1');
// ES6 Minimized
import Moralis from 'moralis-v1/dist/moralis.min.js';

For server-side applications or Node.js command line tools, include 'moralis-v1/node':

// In a node.js environment
const Moralis = require('moralis-v1/node');

For React Native applications, include 'moralis-v1/react-native.js':

// In a React Native application
const Moralis = require('moralis-v1/react-native.js');

// On React Native >= 0.50 and Moralis >= 1.11.0, set the Async
const AsyncStorage = require('react-native').AsyncStorage;
Moralis.setAsyncStorage(AsyncStorage);

Typescript support

Typescript types are supported out-of-the box. The types are defined in /types. These are updated with every release.

changelog

1.13.0 (2023-05-25)

Bug Fixes

Features

1.12.0 (2022-11-03)

Bug Fixes

Features

1.11.0 (2022-08-03)

Bug Fixes

  • casing for tracking keys (e97e9b3)

Features

  • add cronos testnet chainid (1af9726)
  • api: sending sending headers to apis to track activity (0b60aac)

1.10.1 (2022-07-27)

Bug Fixes

  • Add missing ipfs() and hash() methods to Moralis.File type (#346) (83ad897), closes #345

1.10.0 (2022-07-25)

Bug Fixes

Features

  • allow optional properties for magic connect (#528) (bfe8d3d)
  • allow to skip sdk version-check request (#527) (f446af3)

1.9.1 (2022-07-21)

Bug Fixes

  • remove page check when using cursor pagination (#502) (d062682)

1.9.0 (2022-07-13)

Features

  • support web3Auth chain config (14289d9)

1.8.1 (2022-06-28)

Bug Fixes

  • fix pagination manual version bump (fa46929)
  • web3api: paginated result fix (b9453f0)

1.8.0 (2022-05-29)

Features

1.7.0 (2022-05-09)

Features

1.6.0 (2022-05-02)

Features

  • api-pagination: add next() function on response for paginated results (eea34bc)

1.5.11 (2022-04-26)

Bug Fixes

  • deps: bump minimist from 1.2.5 to 1.2.6 (#320) (9207835)
  • update log message if running on node.js (#308) (01ff9f5)

1.5.10 (2022-04-25)

Bug Fixes

  • web3Auth should work when retry after closing modal (d76537a)

1.5.9 (2022-04-08)

Bug Fixes

  • plugin triggers to handle web3sign correctly (#309) (26fc670)

1.5.8 (2022-03-31)

Bug Fixes

  • return exact rate limit response coming from api (#303) (33a05e6)

1.5.7 (2022-03-30)

Bug Fixes

  • deps: bump minimist from 1.2.5 to 1.2.6 (#305) (0e6c490)

1.5.6 (2022-03-29)

Bug Fixes

  • add repository url for semantic release (#307) (13394d1)

1.5.5 (2022-03-19)

Bug Fixes

  • react-native compatibility for v0.64+ (b906444)

1.5.4 (2022-03-16)

Bug Fixes

1.5.3 (2022-03-15)

Bug Fixes

1.5.2 (2022-03-15)

Bug Fixes

  • deps: bump axios from 0.24.0 to 0.26.1 (#288) (240c3f0)
  • deps: bump ethers from 5.5.3 to 5.6.0 (#287) (3632dd6)

1.5.1 (2022-03-15)

Bug Fixes

  • send sessionToken with apiRequest for correct rate-limiting (bef928b)

1.5.0 (2022-03-15)

Bug Fixes

  • deps: bump follow-redirects from 1.14.7 to 1.14.9 (#270) (181edf1)

Features

  • add metrics for start event (28bb292)

1.4.1 (2022-03-15)

Bug Fixes

1.4.0 (2022-03-14)

Features

1.3.5 (2022-03-01)

Bug Fixes

  • prevent deletion of params in api call (#276) (505df2b)

1.3.4 (2022-03-01)

Bug Fixes

1.3.3 (2022-03-01)

Bug Fixes

  • better authentication types for connectors (#274) (d608166)

1.3.2 (2022-02-14)

Bug Fixes

  • use secure signing message for link action (#261) (f3be548)

1.3.1 (2022-02-09)

Bug Fixes

  • FromWei type from number to string (#257) (fdb5804)
  • overloaded functions for executeFunction (#256) (28b2468)

1.3.0 (2022-02-09)

Features

  • add web3Auth as connection method (a7724f1)

1.2.7 (2022-02-07)

Bug Fixes

  • newsession param for walletconnect and magic (a0928dc)
  • prevent cleanup when enabling web3 (01a7cd0)
  • prevent double cleanup on authentication (bc4abe1)
  • types for anyNetwork in enableWeb3 (4573a8a)

1.2.6 (2022-02-04)

Bug Fixes

  • account for metamask disconnect issue (#252) (8664602)

1.2.5 (2022-02-04)

Bug Fixes

  • cleanup web3 on logout (#250) (d676d87)
  • expose setting of 'any' network on provider (#251) (16537fa)
  • preserve sessions for walletconnect and magic (#249) (82c33e6)

1.2.4 (2022-01-31)

Bug Fixes

  • filter console warnings of magic and wc (#238) (dec4e2e)

1.2.3 (2022-01-28)

Bug Fixes

  • type gen for web3Api when no queryparam (#236) (515c86d)

1.2.2 (2022-01-28)

Bug Fixes

1.2.1 (2022-01-28)

Bug Fixes

1.2.0 (2022-01-27)

Features

  • add authentication via MagicLink (9420eb9)

1.1.2 (2022-01-26)

Bug Fixes

  • set default address for Web3API and SolanaAPI (57d15cc)

1.1.1 (2022-01-26)

Bug Fixes

  • avoid duplicate enableWeb3 calls (8df9484)
  • better error message when no appId provided (225a696)
  • expose Moralis.web3Library (59a7c28)

1.1.0 (2022-01-21)

Features

1.0.7 (2022-01-20)

Bug Fixes

1.0.6 (2022-01-20)

Bug Fixes

  • filter out walletconnect dependency warning (#220) (31e94ac)
  • include details on WEB3_DEACTIVATED event (#218) (f2fe3e1)
  • move MoralisWeb3 types to Moralis (#219) (945e79b)

1.0.5 (2022-01-20)

Bug Fixes

1.0.4 (2022-01-20)

Bug Fixes

1.0.3 (2022-01-19)

Bug Fixes

1.0.2 (2022-01-19)

Bug Fixes

1.0.1 (2022-01-17)

Bug Fixes

  • re-add isMetaMaskInstalled (4673e18)

1.0.0 (2022-01-17)

  • Removed dependency of web3.js in favour of ethers.js
  • Introducing custom connectors

BREAKING CHANGES

Moralis.web3 and Moralis.enableWeb3

Moralis.web3 and Moralis.enableWeb3 will now return an instance of Ethers.js instead of an instance of Web3.js. To account for these changes you should

1) Adjust your code to use the Ethers.js library

Or

2) Initialize your own Web3 library by using Moralis.provider

import Web3 from 'web3'
import Moralis from 'moralis'

await Moralis.enableWeb3()
const web3 = new Web3(Moralis.provider)

Return values of Moralis.executeFunction and Moralis.transfer

Return values are changed for Moralis.executeFunction and Moralis.transfer. They are now a transaction response from Ethers.js: This object contains all data about the transaction. If you need data about the result of the transation, then you need to wait for the transaction to be confirmed.

You can do this via transaction.wait() to wait for 1 confirmation (or transaction.wait(5) to wait for 5 confirmations for example):

const transaction = await Moralis.transfer(options)
const result = await transaction.wait()

Moralis.onXXX events have changed

Instead of returning the results from the provider directly, moralis generalizes these events so that they can be used for anny connector: metamask, walletconnect, network etc. A notable change is the renamning of Moralis.onAccountsChanged to Moralis.onAccountChanged

Customize enableWeb3 / custom connectors

Previously, it was possible to overwrite the enableWeb3() function. This allowed for custom implementation to connect wallets that are not supported by Moralis out-of-the-box. This approach is not possible anymore, to allow for better scaling and more consistent behavior.

Instead, now you can implement your own connector, which extends the AbstractConnector class.

This class should implement

  • An activate() function that resolves to an object with:
    • provider: A valid EIP-1193 provider
    • chainId (optional): the chain that is being connected to (in hex)
    • account (optional): the account of the user that is being connected
  • Subscribes to the EIP-1193 events. This should be mostly done automatically by calling this.subscribeToEvents(provider) in the activate function.
  • the type field to indicate a name for the connector
  • (optionally) a deactivate function that extends the default deactivate function. Implement this when you need to clean up data/subscriptions upon ending/switching the connection.

Then you can include this CustomConnector in the authenticate/enableWeb3 call as an option:

Moralis.authenticate({ connector: CustomConnector })

See for example implementations:

0.0.184 (2022-01-13)

  • prevent loading issue when unpkg is down (#192) (4d0f787)

0.0.183 (2022-01-05)

Bug Fixes

  • debug (c426bd7)
  • set correct version during compiling (5723a14)
  • update sdk-check to account for beta branches (077c3f9)

0.0.182 (2022-01-04)

Bug Fixes

  • re-add default decimals value of 18 for fromWei (f127ab2)

0.0.181 (2022-01-03)

Bug Fixes

  • update CDN build version correctly (c3e3044)

0.0.180 (2022-01-03)

Bug Fixes

  • update build version correctly (3ba6a19)

0.0.179 (2022-01-03)

Bug Fixes

  • avoid floating decimals in utils (0a1de0a)

0.0.178 (2021-12-30)

Bug Fixes

0.0.177 (2021-12-30)

Bug Fixes

  • prevent floating error on Moralis.Units.Token (2704e5b)

0.0.176 (2021-12-30)

Bug Fixes

  • web3api type for 201 response (5ad68bb)

Moralis-SDK-JS

0.0.53

Features

  • Initial move from private repository