Moralis Streams Setup Question

Hi, i am setting up the streams for the first time, i watched the video and copied everything from it but get this error.

MoralisError [Moralis SDK Core Error]: [C0015] Key "defaultEvmApiChain" is already registered

Here is the code

const Moralis = require("moralis").default;
const Chains = require("@moralisweb3/common-evm-utils");
const EvmChain = Chains.EvmChain;
const ABI = require("./abi.json");
require("dotenv").config();

const options = {
    chains: [EvmChain.ETHEREUM],
    description: "USDC",
    tag: "usdcTransfers",
    includeContractLogs: true,
    abi: ABI,
    topic0: ["Transfer(address,address,uint256)"],
    webhookUrl: "",
};

Moralis.start({
    apiKey: process.env.MORALIS_KEY,
}).then(async () => {
    const stream = await Moralis.Streams.add(options);
    const { id } = stream.toJSON();

    await Moralis.Streams.addAddress({
        id: id,
        address: ["0x10affebaa3a5f28ab502fa73488070b73f0428e3"]

    })
})

Never mind, SOLVED, issue on my end, had to reinstall moralis

1 Like

Now another issue, i am getting this error not sure how to fix it. I have an epi key setup correctly in .env file, the rest of the app that uses moralis works perfectly but the stream isnt working

MoralisError [Moralis SDK API Error]: [A0003] apiKey is not set

Here is the code, i also entered my apikey on the streams in moralis dashboard to access streams

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");
const express = require('express')
const notifier = require('node-notifier');
const app = express()
require("dotenv").config();
const PORT = process.env.PORT || 6000;

app.use(express.json())

const stream = {
  chains: [EvmChain.ETHEREUM], // list of blockchains to monitor
  description: "Test Token", // your description
  tag: "XXXX", // give it a tag
  webhookUrl: "", // webhook url to receive events,
  includeNativeTxs: true,
};

(async () => {
  const newStream = await Moralis.Streams.add(stream);
  const { id } = newStream.toJSON(); // { id: 'YOUR_STREAM_ID', ...newStream }

  // Now we attach bobs address to the stream
  const address = "0x44aad22afbb2606d7828ca1f8f9e5af00e779ae1";

  await Moralis.Streams.addAddress({ address, id });
})();

app.post('/webhook', (req, res) => {
  const webhook = req.body;
  for (const erc20Transfer of webhook.erc20Transfers) {
    const addrs = `${erc20Transfer.from.slice(0, 4)}...${erc20Transfer.from.slice(38)}`;
    const amount = Number(erc20Transfer.valueWithDecimals).toFixed(0);

    notifier.notify({
      title: 'Test',
      message: `${addrs} just sent \n$${amount}`,
    });
  }

  return res.status(200).json();
});

Moralis.start({
    apiKey: process.env.MORALIS_KEY,
    
  }).then(() => {
    app.listen(PORT, () => {
      console.log(`Server listening on port ${PORT}`);
    });
  })

what line generates that error?

it looks like the api key is set here

I also have this issue and it is not being fixed by updating my version of moralis.

The error is: MoralisError [Moralis SDK Core Error]: [C0015] Key "defaultEvmApiChain" is already registered

const Moralis = require('moralis').default;
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const helmet = require('helmet');
const checkJwt = require('./src/middlewares/checkJwt.js');
const sendErrorResponse = require('./src/middlewares/errorResponseMiddleware.js');

// UTILS
const { httpResponseMessage } = require('./src/utils/responseMessages.js');

// APP SETUP
const app = express();
const port = process.env.PORT;

app.use(cors());
app.use(helmet());
app.use(checkJwt);

async function main() {
  await Moralis.start({
    apiKey: process.env.MORALIS_API_KEY,
  });
}
main().catch((err) => console.log(err));
...

Hey @brandon-blockpass,

What’s the version of moralis SDK are you using?

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.