[Question]: Subscribing to logs with web3JS in NodeJS + Moralis.provider

Hi,

I would like to subscribe to logs in nodejs with web3 and using moralis provider. Tried a couple of different ways.

First:

await Moralis.start({
    serverUrl: MORALIS_SERVER_URL,
    appId: MORALIS_APP_ID,
    masterKey: MORALIS_MASTER_KEY,
  });
const web3Js = new Web3(Moralis.provider);
// here moralis provider is null

Second:

const web3Js = new Web3(MORALIS_SERVER_URL);
// The current provider doesn't support subscriptions: HttpProvider

Is there a way to get a moralis provider in NodeJS?

Moralis.enableWeb3()
// window is not defined

Hi you can use the moralis/node package if you want to use it in a Node app.

const Moralis = require('moralis/node');

Connect with Node.js - Moralis

I know I did that. The problem is the Moralis.provider is null and cannot use it with web3 because I cannot enableWeb3 on nodejs with moralis.

You can get if you use your moralisSecret (scroll down slightly): Connect with Node.js - Moralis

const serverUrl = "";
const appId = "";
const moralisSecret = ""

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

await Moralis.enableWeb3();
const web3Js = new Web3(Moralis.provider);
console.log(Moralis.provider);
console.log(web3Js);
await Moralis.start({ serverUrl, appId, moralisSecret });
await Moralis.enableWeb3();
const web3Js = new Web3(Moralis.provider);

 web3Js?.eth
    .subscribe('logs', { address: ETH_CONTRACT_ADDRESS }
....
// The current provider doesn't support subscriptions: MiniRpcProvider

You’ll probably have to use Web3.js directly if that’s the case.