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 :).