Moralis is not defined trying to migrate to v2

Hi there,

I’m trying to upgrade to Moralis v2 in order to use Streams following this tutorial: https://docs.moralis.io/docs/your-first-stream-using-js-sdk

I’ve npm installed moralis and it’s in my package.json, but when I do the following:

import { EvmChain } from '@moralisweb3/evm-utils';
import Moralis from 'moralis';

Moralis.start({
  apiKey: 'MY API KEY',
});

const streamConfig = {
  chains: [EvmChain.ETHEREUM], // list of blockchains to monitor
  description: 'Monitor Eth Address', // your description
  tag: 'tag', // give it a tag
  webhookUrl: 'https://dev-daoexchange-app.loca.lt/v1/moralis/after-save', // webhook url to receive events,
  includeNativeTxs: true,
};

const newStream = await Moralis.Streams.add(streamConfig); //Failing here with: "Reference Error: Moralis is undefined"
const { id } = newStream.toJSON();

It fails when doing await Moralis.Streams.add as Moralis is undefined.

I’ve set the following env variables:

MORALIS_API_KEY
MORALIS_APP_ID
MORALIS_SERVER_URL

And have confirmed they’re all configured correctly - any idea what could be going wrong?

1 Like

strange that it fails at that line and this line that was used previously worked

you can also try to use the swagger interface directly: https://api.moralis-streams.com/api-docs/