Hi, I try to call a write method from node js. But it says that Moralis.ethersByChain is not a function.
This function is working normally from cloud. Iβm just wondering why not from nodejs?
import Moralis from "moralis-v1/node.js";
import * as dotenv from "dotenv";
dotenv.config();
export async function pay(to, amount) {
await Moralis.start({
serverUrl: process.env.serverUrl,
appId: process.env.appId,
masterKey: process.env.masterKey,
});
const eth = Moralis.ethersByChain("0x13881");
const ethersProvider = new eth.ethers.providers.JsonRpcProvider(process.env.rpcUrl);
const wallet = new eth.ethers.Wallet(process.env.privateKey, ethersProvider);
const contractAddress = await Moralis.Query("ContractAddress").first().attributes.engine;
const contractAbi = await Moralis.Query("Abi").first().attributes.token;
const contract = new eth.ethers.Contract(contractAddress, contractAbi, wallet);
async function pay(contract, to, amount) {
try {
await contract.pay(to, amount, { gasLimit: 5000000 });
} catch (error) {
throw new Error(error);
}
}
pay(contract, to, amount);
}
Any suggestions will be much appreciated.
Here is the error:
P.S. Iβm able to call other Moralis functions like queries and saving to DB, meaning that the SDK is imported correctly.
Thank you