[SOLVED] NodeJS serverside Moralis error (window is not defined)

No. I didnā€™t try with the latest I guess. Please suggest me how to work with that.

you install latest version of the sdk, you can check with Moralis.CoreManager.get("VERSION") what version is running now.

latest version now is 1.7.0

Yes. I am using ā€œjs1.7.0ā€ version. :sob:

in this case, for now, you can use web3 or ethers syntax directly to execute a function with private key

Please give me a sample code of it. It will be helpful for me. Thanks in advance.

you could read on this thread:

Still. I couldnā€™t solve the problem. :sob:

What error(s) do you get? Or is it still the same one?

Still it is same. Moralis SDK connection error. Given the error at the top.

I got everything working fine, using:

await Moralis.start({ serverUrl, appId, masterKey, moralisSecret })

as suggested by Rick, you need to add moralisSecret, but do not remove the other params otherwhise the other functions wonā€™t work anymore !

I wonder why this is not in the doc, and it is really hard to debug from the assert !

2 Likes
await Moralis.start({ serverUrl, appId, masterKey, moralisSecret });
await Moralis.enableWeb3({
  chainId: 0x61,
  privateKey: 'priate_key',
});

This works previously with me but now it is not working. I am getting the same error "window is not definedā€™. I have changed the chain to BSC testnet and Mumbai testnet (changed chain id too). But still it not working. Please let me know how to work with it now.

This stopped working since Moralis discontinued speedy nodes. You can use web3js instead

Please share resource for that with me. That would be great help.

Hereā€™s an example using web3js with a custom rpc which is a similar way to do in nodejs. Nonetheless, you can check out web3js docs. You can also find some blogs out there that explains such

I guess using web3 instance is complicated to code. Is there any other way to enableWeb3 using Moralis?

You will need to use ethers.js or web3.js directly if you want to use a private key to make transactions - you canā€™t use enableWeb3 now. For example with ethers.js.

Sorry for disturbing you again. I am confuse about the httpprovider. Please let me know if I want to work with polygon or binance then from where I will get the httpProvider? Infura doesnā€™t provide any url for binance or polygon.

You can use another node provider like Chainstack.

Yes. I know it but there I have to add credit card and thatā€™s the problem.

You can research other node providers in that case, there are others like Alchemy. Please make a new topic if you have more questions/issues.