Moralis.start() function is not defined after Export

We need to call Wallet Data from Moralis for our Application.
To do that we simply followed the instructions in the Moralis Docs.
The API works on it’s own when called in the terminal, but after exporting it and calling it from a different file it returns the following error:

Cannot read properties of undefined (reading ‘start’)

Here’s the API Code (basically the same as in the Moralis Docs)
Wallet Address and API Key are obviously included in the real code.

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const getWalletData = async () => {
  await Moralis.start({
    apiKey: "My_API_KEY",
  });

  const address = "0xbc...a936f13d";

  const chain = EvmChain.ETHEREUM;

  const response = await Moralis.EvmApi.token.getWalletTokenBalances({
    address,
    chain,
  });

  console.log(response.toJSON());
};

export default getWalletData

I don’t think it makes a difference but here’s how I imported and called it in another file:

import getWalletData from '../../data/utils/getWalletData'
const Dashboard = () => {
getWalletData() 
return (
<>
...
</>
);
};

I’ve already tried:

  • reinstalling Moralis CLI
  • changing JS to TS
  • different methods of importing Moralis

I haven’t found a solution in this forum as well. Any help is appreciated :).

Hey @Valu,

I’m not 100% sure but looks like you try to add Moralis on the FE is that correct? If so, that will not work as the SDK is only for NodeJS backend.

Hey @YosephKS,

thanks, I’m not quite sure what you mean though. It seems to me that in the Docs and Moralis implementation videos they are also implementing the API’s in the Frontend.
E.g.:

Maybe i’m misunderstanding something here.
Do you have a source on how to set it up in the way that you’re referring to?

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.