How to start Moralis with version 2?

How to start Moralis with version 2 for call Cloud functions?

My code:

 Moralis.start({
                    apiKey: process.env.NEXT_PUBLIC_MORALIS_STREAM_API_KEY,
                  });

const {message} = await Moralis.Cloud.run('requestMessage', {
                    address: address,
                    chain: EvmChain.ETHEREUM,
                    network: 'evm',
                  });

But get error: TypeError: Cannot read properties of undefined (reading โ€˜runโ€™)

Why Moralis.Cloud was undefined ?

moralis v2 sdk doesnโ€™t know about cloud functions or about a parse server, it is only used to connect to moralis API, you will have to use parse sdk or moralis v1 sdk if you want to connect to a parse server or to a moralis server

How can I call function requestMessage on Parser Server from client ?

you want to call that in client side? I thought that you were trying to do it server side, in client side you use moralis v1 sdk directly

there is an example here for vanilla JS:

Omg, yes bro.
Because I tried to call from server side and not working.

Can call Cloud function from server side ?

I tried to call Cloud from api of Nextjs which will run server-side.

Can I call api direct to parse-server? what url and param for call cloud function ?

I using Parse still error:

Have function run but could not call Parse.Cloud.run(โ€˜Helloโ€™);

image

image

you want to do it server side or client side?
you can also make a simple http request if you want to call a cloud function

https://v1docs.moralis.io/moralis-dapp/cloud-code/cloud-functions#call-via-rest-api

I want to server-side.
OK, I will try http request to call a cloud function.

I tried axios get method to link but get error unauthorized

image

image

image

that error should be related to the application id, maybe you have to provide it with a different name or maybe that is not the correct application id

OK , thank bro
I will try with appid production

That is appId I set in parse-server
image

Aaa, that is Moralis Key not app parser server

it should be the app id there, not the api key, when you call a cloud function

the url should be different, not http://localhost:1337/server, the url should point to the cloud function that you want to call

I ran parse-server local, my link http://localhost:1337/server.

I will test on production

I mean the end of the url should contain the cloud function name, the start of the url is not the issue

1 Like

Im done with cloud functions but got error with verify function.

I post to url/users for authentication and got error:
image
image

Why I got error?
I signature from client and send to server for verify got error

I donโ€™t know, it looks like you are close. Try to log th parameters sent to verify function

1 Like