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 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.