[SOLVED] Moralis Web3API within Parse Cloud function

I am having a hard time setting up the Web3API on my self-hosted parse server. I built this very simple function to test, and I am getting the following error:

MoralisError [Moralis SDK Core Error]: [C0008] Default instance of Core is not set
    at Function.CoreProvider.getDefault (parse-server/node_modules/@moralisweb3/common-evm-utils/node_modules/@moralisweb3/common-core/lib/CoreProvider.js:10:19)
    at Function.EvmChain.create (parse-server/node_modules/@moralisweb3/common-evm-utils/lib/dataTypes/EvmChain/EvmChain.js:201:52)
    at Function.get (parse-server/node_modules/@moralisweb3/common-evm-utils/lib/dataTypes/EvmChain/EvmChain.js:63:29)
    at parse-server/build/cloud/getFunctions.js:307:48
    at parse-server/node_modules/parse-server/lib/Routers/FunctionsRouter.js:173:16
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  isMoralisError: true,
  code: 'C0008',
  details: undefined,
  [cause]: undefined
}
Parse.Cloud.define("getUserCollection", async (request: any) => {
	try {
		const response = await Moralis.EvmApi.nft.getWalletNFTs({
			address: request.params.address,
			chain: EvmChain.POLYGON,
		});
		console.log(response);
	} catch (e) {
		console.error(e);
	}
});


Dependencies:

"@moralisweb3/common-core": "^2.10.3",
"@moralisweb3/common-evm-utils": "^2.11.1",
"@moralisweb3/parse-server": "2.10.3",
"moralis": "^2.10.3",
        

did you also use Moralis.start somewhere in the code?

  await Moralis.start({
        apiKey: 'API_KEY_HERE',
        // ...and any other configuration
    });

Yes, in index.ts file @cryptokid.

I also tried adding this to the same result

if (!Moralis.Core.isStarted) {
			console.log('starting server')
			Moralis.start({
				apiKey: config.MORALIS_API_KEY,
			});
		}

You can try to add that code in the cloud functions code, somewhere at the beginning of cloud code, with an await

Bizarre, wasn’t working yesterday but today it is.

2 Likes

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