Hi everyone,
Does someone know how to execute contract functions with Moralis on a NodeJS app?
I got the following error:
(node:14564) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined
at InjectedWeb3Connector.verifyEthereumBrowser (/root/nft_generator/node_modules/moralis/lib/node/Web3Connector/InjectedWeb3Connector.js:66:5)
at InjectedWeb3Connector.activate (/root/nft_generator/node_modules/moralis/lib/node/Web3Connector/InjectedWeb3Connector.js:72:10)
at InternalWeb3Provider.activate (/root/nft_generator/node_modules/moralis/lib/node/InternalWeb3Provider.js:65:30)
at Function.enableWeb3 (/root/nft_generator/node_modules/moralis/lib/node/MoralisWeb3.js:215:45)
at executeContract (/root/nft_generator/index.js:112:23)
at process._tickCallback (internal/process/next_tick.js:68:7)
My code looks like:
const executeContract = async () => {
await Moralis.start({
serverUrl: serverUrl,
appId: appId,
masterKey: masterKey
});
// Enable web3
await Moralis.enableWeb3({
chainId: 0x80001,
privateKey: walletPrvKey,
});
const options = {
....
}
await Moralis.executeFunction(options).then((result) => {
console.log(result);
});
}
For additional information, I am using the following libraries: Axios, Moralis, and Express:
// Require .env config settings
require('dotenv').config();
// Include libraries
const axios = require('axios');
const Moralis = require("moralis/node");
const express = require('express');