Hello.
I am try to use this code with NodeJs:
import Moralis from 'moralis/node.js';
import { EvmChain } from '@moralisweb3/evm-utils';
import oConfig from '../config/index.js';
import { sv, empty, addDebugData, ucfirst, writeToLog, getDateTimeDiff } from '../lib/helpers.js';
const sTokenPairContractAddress = '0xAC6C2a9657Dc4192d85179876E47cd1DE159f616';
const sStreamKey = oConfig.services.moralis.keys.sStreamKey;
const abi = oConfig.oPancakeSwap.oABI.sDefaultContract;
const functionName = 'token0';
const address = sTokenPairContractAddress;
const chain = EvmChain.BSC;
await Moralis.start({apiKey: sStreamKey});
const oResponse = await Moralis.EvmApi.utils.runContractFunction(
{
abi,
functionName,
address,
chain
});
console.log(' ');
console.log('runContractFunction');
console.log(oResponse.result);
console.log(' ');
and got this error:
/.../@moralisweb3/core/lib/MoralisCoreProvider.js:10
throw new Error_1.MoralisCoreError({
^
MoralisError [Moralis SDK Core Error]: [C0008] Default instance of MoralisCore is not set
at Function.MoralisCoreProvider.getDefault (/.../@moralisweb3/core/lib/MoralisCoreProvider.js:10:19)
at Function.EvmChain.create (/.../@moralisweb3/evm-utils/lib/dataTypes/EvmChain/EvmChain.js:172:52)
at Function.get (/.../@moralisweb3/evm-utils/lib/dataTypes/EvmChain/EvmChain.js:82:29)
at file:///.../token-get-address-from-pair-address.js:12:24
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12) {
isMoralisError: true,
code: 'C0008',
details: undefined,
[cause]: undefined
}
How I can fix it?
package.json
"dependencies": {
...
"@moralisweb3/core": "^2.7.4",
"@moralisweb3/evm-utils": "^2.7.4",
"moralis": "^2.6.7",
...
}
Thanks.