Что такое moralis js
Перейти к содержимому

Что такое moralis js

  • автор:

Moralis SDK (JavaScript / TypeScript)

The most powerful Web3 library for your backend in Javascript and Typescript.

Features:

  • Web3 authentication
  • Make Evm API and Solana API calls
  • Subscribe to real-time blockchain updates via Streams
  • Consistent data types and utilities
  • Modular package: include only what you need
  • Fully Typescript ready out-of-the box

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

�� Demos

If you want to see how to integrate Moralis on your codebase, check out our demos

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

Moralis — building Web3 dApps made simple

Finally, I had some time to dive into Moralis. I’ve wanted to play with it for some time, and lately, I built something simple and tested it. So what is Moralis? They describe this project as a set of tools and services which helps to build serverless, decentralized apps. Worth mentioning is that the face of Moralis is a well-known YouTuber Ivan on Tech.

What tools and APIs it incorporates

Moralis is a service that aggregates many different tools and APIs and works as a glue for them all. All that is needed when developing a decentralized app that requires access to the blockchain, like Ethereum or Binance Smart Chain. So, what will we find there? First of all, it isn’t just about blockchain. You’ll get full-featured user management, standard authentication using password and email, and crypto authentication using Metamask. You’ll also find data management tools, storage in the cloud, and file storage, including IPFS support with pinning services. Besides that, you’ll get similar functionality to web3.js and even static site hosting. So there is a lot. I would also like to write about some of the small red flags, in my opinion, but first, let’s go through what I’ve tested and what is great.

My simple demo

Before we start digging into Moralis, let’s see what I have in the repository. I built a simple, a little bit messy website with only one JavaScript file, one HTML, and one CSS. Without any additional libraries etc. To see how much functionality I’ll be able to get with such little code.

You can find it here:

The demo shows three main areas:

  1. Authentication and interactions with Ethereum blockchain.
  2. Interaction with Moralis data storage.
  3. Files upload handling and IPFS usage.

Here is a quick walk-through video:

How to start with Moralis

Your first step should be the documentation: docs.moralis.io. You’ll find how to create your account there and your first Moralis server. When you get it running, what you need is to get your API Id and your server URL and initialize Moralis in your app. See how I’ve done it here. You’ll also need to include Moralis SDK. In our case, for a simple website, it is enough to include libraries in the head of the HTML document, like here (you need web3.js and moralis.js). When you need to work with Moralis on the Node backend or in React Native app, you can use the npm package for such use cases. You’ll find it here: www.npmjs.com/package/moralis.

In my example, my webpage will expose the API Id, and anyone can use it. But there are many different ways to secure that. This is just a simple demo, and the topic is another article.

After configuring the Moralis server and basic app scaffold, the next step is to look at the authentication tools and flow.

Authenticate with Metamask

Moralis gives you standard authentication flow with username and password, but we will focus on crypto auth. To test that, you will need to have Metamask with configured wallet address for the Ethereum testnet. It can also be Binance Smart Chain or even Polygon. I used Ethereum Goerli testnet.

Moralis gives three functions that will be helpful here. They will handle three processes:

We will need to check if user is already logged in to adjust our UI. This is done by using:

For authenticating the user we can use:

For logging out the user:

You can check how it is implemented in my small demo here.

Get blockchain data

When you are logged in, you can do a couple of things on the chain using the Moralis.Web3API.account instance. For example, to be able to list all transactions, you can use:

You can provide the chain id here and the address of the logged-in user.

Besides this one, you can also list tokens, including NFTs. For more info on these functions, check the docs here. Moralis utilizes web3.js. This is why this library is included as a dependency. So the best would also be to check web3.js docs. I am sure that not all functions are mapped but probably more than in the Moralis docs.

If you want to check how it is implemented in my small demo. Here is an implementation for listing my transactions: Get transactions.

Data storage and queries system

Moralis integrates Parse SDK to handle all queries for stored data. Basically this is very extensive platform. Moralis introduced Moralis.Object concept. Every object with key-value pairs can be treated as collection of data. So every such instance represents real place in the storage. For example if you need to save some data, you’ll use:

You can also query and find all or some of the notes.

Check how it is implemented in my demo:

File storage and IPFS

With Moralis, you can also handle file uploads. There is a concept of Moralis.File, which gives you a couple of functions to handle uploads and get the files back. What is most interesting they give you the possibility to use IPFS with auto pinning, so you don’t have to worry about that.

IPFS is very important in the blockchain area because it is a distributed P2P network that hosts the files without any centralized authority. I will probably write some more about it in separate articles.

In my demo I used IPFS and Moralis.File to be able to send images and then list them back for logged in users. For doing that you will use couple of functions:

To get the IPFS gateway URL to the file, you will need to call fileObject.ipfs() . Of course, you can always take the IPFS CID and use it with other gateway or even in Brave browser, which supports IPFS protocol.

Missing in the docs?

Moralis looks very promising, and building with it is speedy and convenient. So from the developer perspective, I would say that it is a good set of tools, especially for quick prototyping, hackathons, and projects where the time of development is everything (so, almost all in the crypto space ;)).

Unfortunately, there are some red flags for me, although maybe some of them are my lack of info:

  1. I couldn’t find any firm information about the future and how much it will cost to use it. Because if I would like to build something real now, I would need to know the overall cost in the long run.

☝️ Update ☝️ The information on this one could be found in the Discord server:

Our mission is to make this infrastructure available to as many developers as possible. No matter the budget, you can use Moralis to build your dapp and go to market quickly. Therefore Moralis will always have a very generous free plan. Exact pricing for dApps requiring bigger infrastructure will be released in the coming weeks.

It is satisfactory for me. I imagine it as something like Netlify when it comes to pricing plans. They also have a very generous free plan, and if someone needs something more, prices are still affordable.

  1. I also couldn’t find more info about the architecture behind it. So, for example, which cloud services providers are responsible for whole DevOps processes and stuff. Or on how many third-party companies it depends, etc.
  2. Also, with my little current knowledge and experience with Moralis, I am unsure about security and all that API keys stuff. All examples show how to expose these keys to the public in the browser etc. Maybe using Moralis on the server-side should be a better solution, but you’ll need to have a server, so the narration about serverless is not accurate then. I don’t know. There is, of course, an ACL mechanism, and it probably solves a lot, but I still have some uncertainty about this topic here.

The App ID is meant to be public and is included in all requests to Moralis. It’s ok to include the App ID in a public code repository like Github. With the App ID a user can create accounts and call any Cloud Functions. To control when new users can sign up use a beforeSave trigger on the User collection. To learn more about how to lock down your app see the Security docs. What you want to protect is the Master Key as that can override all permissions and has full access to read, write, and delete. It’s best use the Master Key only on the server (i.e. Cloud Functions), never use the Master Key in the front end.

It is an excellent use case for server-side hooks for cloud functions to check and validate the data operations. So before any operation, you can fire your validation and approve or reject the process.

  1. I also wonder what if Moralis will someday disappear. Is there a way to export all my data and configuration and reuse it in some custom setup? Will we get such instructions somewhere?

Summary

Despite a couple of inconveniences, I am sure that Moralis has strong fundamentals to be an excellent developer service for blockchain integrations and overall apps, not only dApps.

I love how simple it is to use a couple of functions and make the app fully functional. I spend a little time writing a tiny amount of code and achieving a fully functional application that connects with blockchain data, sends files to IPFS, and adds/removes items in the data store.

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Moralis Official Javascript SDK

License

MoralisWeb3/Moralis-JS-SDK

Name already in use

  • Local
  • Codespaces

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more about the CLI.

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Moralis SDK (JavaScript / TypeScript)

The most powerful Web3 library for your backend in Javascript and Typescript.

Features:

  • Web3 authentication
  • Make Evm API and Solana API calls
  • Subscribe to real-time blockchain updates via Streams
  • Consistent data types and utilities
  • Modular package: include only what you need
  • Fully Typescript ready out-of-the box

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

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 :

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

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

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

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

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

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:

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

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.

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

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

The main modules of the SDK

package changelog description
moralis CHANGELOG.md The main package of Moralis containing all features. You probably are looking for this one.

Integrations with frameworks and services

package changelog description
@moralisweb3/next CHANGELOG.md Integration of Moralis in NextJs
@moralisweb3/parse-server CHANGELOG.md Integration of Moralis in parse-server

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

package changelog description
@moralisweb3/auth CHANGELOG.md Authenticate via web3
@moralisweb3/evm-api CHANGELOG.md Make calls to the Evm blockchain via Moralis Evm Apis
@moralisweb3/sol-api CHANGELOG.md Make calls to the Solana blockchain via Moralis Solana Apis
@moralisweb3/streams CHANGELOG.md Subscribe to realtime data from the blockchain

Core modules are the building blocks of Moralis.

package changelog description
@moralisweb3/common-core CHANGELOG.md All core logic related to the SDK

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

What is Moralis? A Useful Intro.

What is Moralis? A Useful Intro.

With Moralis, you can create sophisticated DApps in minutes with just a few lines of code. It’s a fully managed and infinitely scalable Web3 platform that allows you to launch projects in minutes instead of weeks. One of Moralis’ greatest strengths is its accessibility. as a developer, this allows you to focus more on creating exceptional Web3 experiences with just a few lines of code. Do not waste your time reinventing the blockchain wheel, when you can be creating more valuable products like useful Dapps.

What is Moralis?

The Moralis service aggregates many different tools and APIs and serves as the glue between them. everything is needed to develop a decentralized app that works with blockchains, like Ethereum or Binance Smart Chain. In addition to different blockchain utility functions, developers will also get full-featured user management, standard authentication with passwords and emails, as well as crypto authentication using Metamask. as well as data management tools, cloud storage, and file storage, IPFS pinning services will be available. Another utility for developers is that they get similar functionality to web3.js and even static site hosting. As a result, there are many tools that make our life easier and faster. However, as this project is at the early stages of development, there could some downsides to it which we will cover in this article.

Moralis SDK

With Moralis SDK, A few lines of code with the Moralis SDK (Software Development Kit) are all that’s required to quickly add authentication for crypto wallets, users database such as tokens, and addresses to your project. Moreover, Moralis SDK works with both React and React Native; developers can now quickly build mobile and web Dapps.

Cloud Code

The Moralis server provides an advantage for heavy computation calculations by utilizing its own cloud server. You write it in a cloud server instead of writing it on the client side and invoking it. either schedule the function to get executed or invoke it from the client side. Dapps never have to perform hard and long and heavy mathematical calculations because cloud code handles the heavy computational logic on its own servers.

Moralis Database

Moralis servers handle the data of your Dapps by virtue of their name; For example, if you authenticate with a crypto wallet such as Metamask, the Moralis database will automatically store the authenticated user addresses, token balances, etc. Providing swap tokens, showing user details, transaction histories, etc., is easy with this feature.

What is IPFS and How does it work?

Interplanetary File System (IPFS) is the name of this versioned file system, which stores files and tracks versions over time, much like Git does. Additionally, IPFS defines how file transfers across a network, making it a distributed file system, similar to BitTorrent. These two properties combine to create a permanent web, enhancing existing internet protocols like HTTP with a new permanent web.

Just as blockchains rely on nodes for their computing power, IPFS has hundreds of thousands of nodes that offer their storage bandwidth to store the files and upload the content to the network. As a result, Wikipedia’s content would have been stored across a distributed network instead of a central server if it had used IPFS for storage. Users can access a particular page by entering the link to the node storing that page if one of the nodes storing it is online. The same applies to other platforms, websites, and apps. We will cover a complete article on IPFS in our fore-going contents.

IPFS in Moralis:

In Moralis, file uploads are also possible. There is a concept called Moralis File, which gives you a bunch of functions to handle uploads and get the files back. Most interestingly, they offer IPFS with auto-pinning, so you don’t have to worry about it. As a distributed P2P file sharing network, IPFS is very important in the blockchain area.

Moralis alternatives and competitors

1. DappVolume:

DappVolume is a platform that lists Dapps (Decentralized Applications) and users of dApps. The data provided on the platform gives historical transaction data, as well as volume and user interaction data. DappVolume allows transactional, volume, balance, and users of each dApp in 1h, 24h, 7d, and all-time increments. Only DV shows all-time data.

2. Thirdweb:

Builds features such as NFTs, marketplaces, tokens, and more in a few clicks Utility SDKs, widgets, and interfaces to integrate web3 features into your app. It powers blockchain games, DAOs, NFT card platforms, generative art drops, and more.

3. Dapp Store:

Dapp Store is a platform, which lists all popular Dapps (decentralized applications). Discover the innovative world of blockchain, plus explore the many decentralized applications in our platform. Dapps are ranked by DAU and it shows their real popularity and usability of the Dapp.

4. Chainstarters:

Chainstarters is a powerful, rapid, web3-enabled platform for software developers. It eliminates the burden of setting up and maintaining a secure and scalable infrastructure. This allows you to focus on creating amazing technology.

5. Dappy Wallet:

Dappy is open source light wallet powered by Blockstack. It uses Gaia decentralized storage and encryption option. Dappy doesn’t store or proceed user’s private key, all data are securely stored in Gaia. Built-in exchange is supported by ShapeShift. Dappy was created by BC Net which trusts in crypto and decentralized applications.

6. Bunzz:

Using Bunzz, you can build your own tokens, NFT, DeFi Dapp, NFT Marketplaces, and more in a few clicks with our GUI Best Back-End solution for Dapp developers as well as allowing them to upload their own new modules. You can easily integrate web3 features into your app using Bunzz SDK.

Wrapping Up

3d websites

Arashtad Custom Services

In Arashtad, we have gathered a professional team of developers who are working in fields such as 3D websites, 3D games, metaverses, and other types of WebGL and 3D applications as well as blockchain development.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *