CLI

A Command Line Interface (CLI) - Update Cloud Code and Plugins on the Server Faster and Easier.

Initial Setup

To use the Moralis Admin CLI, you need to install it by running the following code in the terminal:

npm install -g moralis-admin-cli

To see the complete list of available commands, run the help command:

moralis-admin-cli help

To get further information about a command, append helpto the command:

moralis-admin-cli watch-cloud-file help

Arguments to the Commands

You can specify the arguments for each command in a combination of three ways:

1. Inline Arguments

You can specify the arguments inline by either the short or long flag:

moralis-admin-cli watch-cloud-file --moralisApiKey 4fj5edfj553jdj5jfd
# Or
moralis-admin-cli watch-cloud-file -k 4fj5edfj553jdj5jfd

2. Use an .env File

You can place most arguments in a .env file:

moralisApiKey=4fj5edfj553jdj5jfd
moralisApiSecret=5jd7kg3kd9d93jfljkb
...

By doing this, you don't need to specify the arguments inline as long as the .env file is located in the directory that you are running the command from.

3. Use Environment Variables

You can also store the arguments as environment variables on your local machine.

To do this on a Windows machine, press the "Windows Key" and type "environment variables".

Select "Edit the system environment variables":

Select "Environment Variables":

Select: "New":

Input the name and value for the variable and press OK:

Repeat for each variable you want to store.

watch-cloud-folder

You can write your cloud functions in your preferred IDE by using the moralis-admin-cli.

Here is how you can use CLI to upload all JS files in a folder as cloud code. All files will be merged together.

moralis-admin-cli watch-cloud-folder --moralisApiKey API_KEY --moralisApiSecret API_SECRET --moralisSubdomain SERVER_URL --autoSave 1 --moralisCloudfolder PATH
How to write cloud functions locally on your machine, use multiple files and upload to the server.

After you've run the command, the cloud code will be updated automatically on the backend with each save!

connect-local-devchain

In order to use this command, you need to have frpc on your computer. You can get it here: https://github.com/fatedier/frp/releases.

You can now run the following command to start the process (Insert your own key, secret, and path):

moralis-admin-cli connect-local-devchain --moralisApiKey FAM6pYzBKjcM
--moralisApiSecret 7thQGNKKqX8s --frpcPath "C:\Program Files\frpc\frpc.exe"

To get more information you can write:

moralis-admin-cli connect-local-devchain help

This will show you a more detailed description of the command and show how you can call the command without the need to specify the arguments each time.

You can leave out the arguments if you follow option 2 or 3 in the Initial Setup section.

update-server

You can update and restart your Moralis servers from the command line by using the update-servercommand.

You can now run the following command to start the process (Insert your own key, secret, and path):

moralis-admin-cli update-server --moralisApiKey FAM6pYzBKjcM
--moralisApiSecret 7thQGNKKqX8s

To get more information you can write:

moralis-admin-cli update-server help

This will show you a more detailed description of the command and show how you can call the command without the need to specify the arguments each time.

You can leave out the arguments if you follow option 2 or 3 in the Initial Setup section.

create-server

You can create new Moralis servers from the command line by using the create-servercommand.

Run the following command to start the process (Insert your own key, secret, and path):

moralis-admin-cli create-server --moralisApiKey FAM6pYzBKjcM
--moralisApiSecret 7thQGNKKqX8s

To get more information you can write:

moralis-admin-cli create-server help

This will show you a more detailed description of the command and show how you can call the command without the need to specify the arguments each time.

You can leave out the arguments if you follow option 2 or 3 in the Initial Setup section.

add-contract

You can choose to listen and sync smart contract events to your Moralis servers from the command line by using the add-contractcommand.‌

Run the following command to start the process (Insert your own key, secret, and path): exit: Ctrl+↩

moralis-admin-cli add-contract --moralisApiKey FAM6pYzBKjcM
--moralisApiSecret 7thQGNKKqX8s --abiPath ".\MyContract.json"

To get more information you can write:

moralis-admin-cli add-contract help

‌This will show you a more detailed description of the command and show how you can call the command without the need to specify the arguments each time.‌

You can leave out the arguments if you follow option 2 or 3 in the Initial Setup section.

deploy

You can deploy your dApp to be hosted on Moralis using the deploy command.

The only two required parameters are moralisApiKey and moralisApiSecret.

The command will default to deploying the contents of the folder from where the command is executed.

If you want to specify another folder, you can do that by using the --folderPath or -p flags.

Example:

moralis-admin-cli deploy --p C:\myDapp\

You can also choose to specify the server to deploy to by using the --moralisSubdomain or -d flags.

Example:

moralis-admin-cli deploy --d dajbrubkfnoi.moralis.io

If the --moralisSubdomain or -d flags are left out, you'll get to choose from a list of your servers.

To get more information you can write:

moralis-admin-cli deploy help

This will show you a more detailed description of the command a show how you can call the command without the need to specify the arguments each time.

You can leave out the arguments if you follow option 2 or 3 in the Initial Setup section.

undeploy

You can remove your deployed dApp from a Moralis server by using the undeploy command.

The only two required parameters are moralisApiKey and moralisApiSecret.

You can choose to specify where the server should undeploy to by using the --moralisSubdomain or -d flags.

Example:

moralis-admin-cli undeploy --d dajbrubkfnoi.moralis.io

If the --moralisSubdomain or -d flags are left out, you'll get to choose from a list of your servers.

To get more information you can write:

moralis-admin-cli undeploy help

This will show you a more detailed description of the command and show how you can call the command without the need to specify the arguments each time.

You can leave out the arguments if you follow option 2 or 3 in the Initial Setup section.

get-logs

You can get real-time logs from Moralis by running the "get-logs" script.

moralis-admin-cli get-logs --moralisApiKey MORALIS_CLI_API_KEY --moralisApiSecret MORALIS_CLI_SECRET_KEY

This command prints logs from Moralis in your terminal and gives real-time information about errors and warnings generated by the Moralis Server.

Make sure to run the "help" command to find out more.

moralis-admin-cli get-logs help