[SOLVED] Application with self hosted server

Hi

I have build Parse-server migration with my credentials and also the client application both from GitHub mainly for authentication and the server and client are both working. In my own application I had used Ethereum moralis server and now since its removed, I have used self hosted server same way as the GitHub client, it worked with my database as well, but I’m getting error in my application.

Error: You need to call Moralis.start with an applicationId before using Moralis.

I have used same handleauth method from the GitHub client application. I’m using reacts. Checked all forums but it says to use initialize. not sure where to use it as its not used in the GitHub client application. Link for the method used

Thanks

this error is from react?

for what line you get this error?

Yes, client application

we may need more info about your application, did you set the server url and app id in the react application?

Yes, I used Moralisprovider and set the aphid and server url in the app.js.

Github client application worked without any problem with the server with my credentials. same method not working in my application.

return (


<Component {…pageProps} />


);

what is the line that gives you that error?

const handleAuth = async (provider) => {
try {
setAuthError(null);
setIsAuthenticating(true);

  enableWeb3({ throwOnError: true, provider });
  
   const { account, chainId } = Moralis;
  console.log(account);
  console.log(chainId);
  if (!account) {
    throw new Error(
      'Connecting to chain failed, as no connected account was found'
    );
  }
  if (!chainId) {
    throw new Error(
      'Connecting to chain failed, as no connected chain was found'
    );
  }

  // Get message to sign from the auth api
  const { message } = await Moralis.Cloud.run('requestMessage', {
    address: account,
    chain: parseInt(chainId, 16),
    networkType: 'evm',
  });

  // Authenticate and login via parse
  await authenticate({
    signingMessage: message,
    throwOnError: true,
  });
  onClose();
} catch (error) {
  console.log(error);
  setAuthError(error);
} finally {
  setIsAuthenticating(false);
}

};

In catch error I get the error

========

Also inside handleauth

const { account, chainId } = Moralis;

is not picking up account . it is picking up account only globally.

server application terminal shows
info: Ran cloud function getPluginSpecs for user undefined with:
Input: {}
Result: [] {ā€œfunctionNameā€:ā€œgetPluginSpecsā€,ā€œparamsā€:{}}

does it get to execute this line?

you can try to use await Moralis.start(... )

it looks like this is how Moralis is imported

import Moralis from 'moralis-v1';

Moralis.Cloud is getting called as I can see it in the server terminal information


info: Ran cloud function getPluginSpecs for user undefined with:
Input: {}
Result: [] {ā€œfunctionNameā€:ā€œgetPluginSpecsā€,ā€œparamsā€:{}}


where should I put moralis.star(…) ?

also I have imported using
import Moralis from ā€˜moralis-v1’

you can put it after you imported it, you have to provide the serverUrl and appId as parameters

that getPluginsSpec can be from somewhere else in the code

await Moralis.start(moralisServerURL, moralisAppId);

  // Get message to sign from the auth api
  const { message } = await Moralis.Cloud.run('requestMessage', {
    address: account,
    chain: parseInt(chainId, 16),
    networkType: 'evm',
  });

My server url is
const moralisServerURL = ā€˜http://localhost:1337/server’;

Now I get this error

Error: Moralis.start failed: serverUrl is required

you have to use specific variable names if you are using that syntax, not moralisServerURL, it could be serverUrl=moralisServerURL, moralisServerURL alone doesn’t work as expected

await Moralis.start(
(serverUrl = { moralisServerURL }),
(appId = { moralisAppId })
);
same error

ReferenceError: serverUrl is not defined

Try to hardcode the values then

I tried hardcoding the value. same error.

Iam using version ā€œmoralis-v1ā€: ā€œ^1.11.0ā€,

What is the syntax that you tried?

await Moralis.start(
(serverUrl = ā€˜http://localhost:1337/server’),
(appId = 154)
);
console.log('serverurl is: ’ + moralisServerURL);

console is not printing…it is directly going to catch error

Try without so many brackets. Only Moralis.start(serverUrl=n, appId=m)

tried it…but its auto taking taking brackets

await Moralis.start(
(serverUrl = ā€˜http://localhost:1337/server’),
(appId = 154)
);

same error