Self-hosting your Moralis server

It looks like that address and port combination is already in use

Ahh thanks. I had the server up on the separate terminal. Closed that out and it looks good. Thank you

1 Like

Hi Team, Please advice on below:
a. I have my ā€˜parse dashboardā€™ up and also modified one cloud function job but when trying to schedule jobs it says it is not supported.

b. Where in parse server the setting for email will go that we did on Moralis dashboard as attached in screen shot below. It is giving ā€˜Failed to send email because no mail adapter is configured for Parse Server.ā€™
image

Thank You

for jobs you have to install a separate module
for example this one could work: https://www.npmjs.com/package/parse-server-jobs-scheduler

for a mail updater, maybe this one helps you:

Thank you, the job scheduler works well.

Will check on email adapter.

Thank you so much, using sendgrid I was able to setup emails too.

1 Like

I have a few questions regarding the self hosted Moralis server. Help would be appreciated.

  1. In the tutorial, only a client side (React) is connected to the self hosted server. What I actually want is to connect my express backend and send the request to the self hosted Moralis server. How is that possible? Iā€™m currently using the moralis/node package in my express server and using the following code to start the Moralis client on the express server ->
await Moralis.start({
        serverUrl: config.get('moralis.serverUrl'),
        appId: config.get('moralis.appId'),
        masterKey: config.get('moralis.masterKey')
      });

Iā€™m trying to replace my cloud hosted Moralis server with the self hosted one and use the self hosted serverā€™s config in this config object.

Please tell me how can I do so?

  1. When I do enter the config for my self hosted server here, the existing functions do not work. The function Iā€™m using for example is
const NFTs = await client.moralis.Web3API.account.getNFTs({
          chain: options.chain,
          address: addressList[numAddress]
        });

where client is the Moralis client started in point (1). When I try to run this function the parse server is doing nothing and my express server is getting an error error? Error: unauthorized at Function.fetchFromServer.

How can I solve this authentication error when Iā€™m connecting a backend with a backend.

  1. Iā€™m not sure if I can directly use the getNFTs function the way Iā€™ve tried above. If not, could someone please guide me if I have to create a cloud function for this and use the Moralis.evmApi on the hosted server to do so.

Thanks.

Are you using moralis-v1? The link you posted is for the 2.0 SDK which doesnā€™t involve Moralis servers.

If you are, then yes you can use import Moralis from moralis-v1/node in your Express.js server - you are already using your server details correctly in Moralis.start (if those variables are from your self-hosted server).

Installing the latest moralis-v1 should fix this (issue where you have to be authenticated to call the API).

Hey glad, thanks for the quick response.

Yes, the package version Iā€™m using is ā€œ1.7.0ā€. Shall I replace moralis in my express serverā€™s package.json with ā€œmoralis-v1ā€ ?

And if the authentication error gets fixed, what about the getNFTs call? Would that work just the way it is right now or would I have to make any change?

Yes you would need to update to get past the unauthorized error - you shouldnā€™t need to make a change with the API code. As moralis-v1 is a separate package, you can just install it, change the import to moralis-v1 in your code, and test it first (and any other Moralis functions you are using).

Using the moralis-v1 package did get rid of the unauthorized error but Iā€™m still not getting any response for the request from the self hosted server. Note: The request is client.moralis.Web3API.account.getNFTs()

The logs on the self hosted server are as follows ->

info: Ran cloud function getPluginSpecs for user undefined with:
  Input: {}
  Result: [] {"functionName":"getPluginSpecs","params":{}}

What is client referring to in this case? Where is it declared in your code? You can use moralis-v1 like:

const Moralis = require('moralis-v1/node');

...

Moralis.start({ ... });

...

const nfts = await Moralis.Web3API.account.getNFTs({
    chain: '0x1',
    address: '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d',
});

console.log("nfts", nfts);

This looks fine.

Iā€™m sorry, client is nothing but a wrapper around the Moralis object.

Iā€™m using the same code as you have pointed out.

await Moralis.start({ serverUrl: config.get('moralis.serverUrl'), appId: config.get('moralis.appId'), masterKey: config.get('moralis.masterKey') });

And after starting it ->

const NFTs = await client.moralis.Web3API.account.getNFTs({ chain: options.chain, //The chain to be queried 'eth' address: options.address //The address string }); console.log('here???', NFTs);

The problem is that the self hosted server is not returning anything and the request is getting timed out on my express server side.

Iā€™m sorry, client is nothing but a wrapper around the Moralis object.

Can you show how youā€™ve done this?

Can you please use Moralis.Web3API.. like above just to be sure it is not an issue with your Express.js server code.

you do this server side? that one with Moralis.start and with masterKey there

Iā€™ve tried this as well. Same thing. The fact that the self-hosted server is receiving the request but not responding is the issue I guess?

Sorry I did not understand you, Iā€™m doing the Moralis.start() on my express server side yes. The config object has the serverUrl and other parameters of my self hosted server.

in that case you need to use moralis v1 sdk for that syntax and after that you have to use the same object for web3api

you can also use moralis v2 sdk in backend where you only need the api key (this would be the recommended way)

how to get the clientID and rpcTargetā€¦are they related to the self hosted serverā€¦where can i find them?
@cryptokid

Hi Team,

I have now other open item related to saveIPFS() not working with the parse server. Could you please advice how to fix. Thank You