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

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.