Self-hosting your Moralis server

Try using account, chainId from useMoralis instead of const { account, chainId } = Moralis;:

const { account, chainId } = useMoralis();

You may need to comment out these statements:

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');
  }

Because the state updates won’t be synchronous so these will probably fail.


do you recommend I change the name of the function? how should it be named?

You need to use that hook at the top of the function component similar to the other useMoralis:

export const AuthenticateModal = ({ isOpen, onClose }: AuthenticateModalProps) => {
 // in your case, it's function Account() - there are already hooks you are using here
  const { authenticate, enableWeb3 } = useMoralis();
  // can add account, chainId
  

This is a React concept not related to Moralis.

image
still not working

small update. I used the address from
const { walletAddress, chainId} = useMoralisDapp();

it is requesting to sign now. However I have problems with others
image

this is NativeBalance hook

import { getNativeByChain } from “helpers/networks”;

import { useMoralisDapp } from “providers/MoralisDappProvider/MoralisDappProvider”;

import { useEffect, useMemo, useState } from “react”;

import { useMoralis, useMoralisWeb3Api, useMoralisWeb3ApiCall } from “react-moralis”;

export const useNativeBalance = (options) => {

const { account } = useMoralisWeb3Api();

const { Moralis } = useMoralis();

const { chainId, walletAddress } = useMoralisDapp();

const [balance, setBalance] = useState({ inWei: 0, formatted: 0 });

const nativeName = useMemo(() => getNativeByChain(options?.chain || chainId), [options, chainId]);

const {

fetch: getBalance,

data,

error,

isLoading,

} = useMoralisWeb3ApiCall(account.getNativeBalance, {

chain: chainId,

address: walletAddress,

...options,

});

useEffect(() => {

if (data?.balance) {

  const balances = {

    inWei: data.balance,

    // missing second argument (decimals) in FromWei function,

    formatted: Moralis.Units.FromWei(data.balance),

  };

  setBalance(balances);

}

// eslint-disable-next-line react-hooks/exhaustive-deps

}, [data]);

return { getBalance, balance, nativeName, error, isLoading };

};

does this code need to be modified too?

You’re getting these errors after you authenticate?

If it’s before, it may be related to this issue.

can you explain what ‘x-parse-application-id’ and ‘appidhere’ are? I will try to see if that fixes it

in my .env for self server app id =001

Yes you would put in your own server’s appId. x-parse-application-id is the name of the header that is needed to get past the unauthorized (403 Forbidden) issue if you are not authenticated.

I am not sure if that issue is related to yours exactly but you can try it.

it worked! thanks for the help! I am having another issue a bit unrelated I created another issue

Hello,

In my cloud functions, there is a param which is array of string. (request.params.pendingSlots)

Parse.Cloud.define(‘startBattle’, async (request: { user: { get: (arg0: string) => any; }; params: { wallet: string; mainOwner: any; lang: string; roosterId: string; pendingSlots: string[]; }; }) …

however, when I read it in the function, it becomes string. For example (I used Postman):

request.params.pendingSlots = [“142218”, “0”, “0”, “0”,“0”, “0”, “0”]

–> it returns request.params.pendingSlots[2] = 1 which is the second character, not the second item in the array

Am I sending Post request incorrectly via Postman? or how should I modify the cloud function declaration?

Thanks

I don’t know about the function declaration, all parameters are found in request, you can use console.log(JSON.stringify(request)) to see how it looks

all the parameters should be in a json format that you can parse in order to extract the data

maybe you have to do a json parse for that request.params.pendingSlots in order to get the list

Hi Team, I have my dApp on the free plan and looking to self host the server and migrate all functionalities currently we are using in the application. Will there be any issues in working on the migration past Dec 1st?

the server will be archived on 1 December, you can do a backup of the database before that, and for all the settings that you have or cloud code

I got “Parse.bulkUpdateMany is not a function” in the cloud functions. How should I update this function?

Thanks

you could connect directly to mongo db now too from cloud code in order to run a bulk update

Thanks.

So, there isn’t a equivalent function to do bulkUpdateMany in the Parse object?

  • And how to “connect directly to mongodb from cloud code”? Do you have an example?

Thanks

there isn’t an equivalent for that in the Parse sdk, you connect directly by importing mongo db and using it

similar to how it is used here
https://v1docs.moralis.io/moralis-dapp/database/direct_access#node.js

1 Like

Some wallets is receiving this error message while logging in “invalid session token”, while most of the wallets can login successfully.

If the error wallet logs in to the current Moralis Server, it works normally.

What should be the problem?

Thanks

is anything specific to those wallets? did you delete anything from user table and from ethAddress table before?

those wallets that don’t work, do they have data in ethAddress table or in User table?

if you try to delete a user you have to delete from both User table and from ethAddress table

Hi,

I haven’t imported ethAddress table to the new database yet. Those wallets that work, they can login without the ethAddress table :slight_smile:

Do we really need to import ethAddress table? I don’t see it is generated in the self-hosted server.