Network change ethereum to polygon

good day, i am trying to switch the netwok from ethereum to polygon as i am buulding dex website but i am having this error:

MoralisError [Moralis SDK Core Error]: [C0015] Key ā€œdefaultEvmApiChainā€ is already registered

see the code below in index.js file

// Import Moralis
// const Moralis = require('moralis').default
// Import the EvmChain dataType
const { EvmChain } = require("@moralisweb3/evm-utils")


const express = require("express");
const Moralis = require("moralis").default;
const app = express();
const cors = require("cors");
require("dotenv").config();
const port = 3001;
const chain = EvmChain.POLYGON

app.use(cors());
app.use(express.json());

app.get("/tokenPrice", async (req, res) => {

  const {query} = req;

  const responseOne = await Moralis.EvmApi.token.getTokenPrice({
    address: query.addressOne,
    chain,
  })

  const responseTwo = await Moralis.EvmApi.token.getTokenPrice({
    address: query.addressTwo,
    chain,
  })

  const usdPrices = {
    tokenOne: responseOne.raw.usdPrice,
    tokenTwo: responseTwo.raw.usdPrice,
    ratio: responseOne.raw.usdPrice/responseTwo.raw.usdPrice * 11031 * responseTwo.raw.usdPrice
  }
  

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

Moralis.start({
  apiKey: process.env.MORALIS_KEY,
}).then(() => {
  app.listen(port, () => {
    console.log(`Listening for API Calls`);
  });
});










Hi @oweal

Can you try using the latest moralis sdk version?

You are using an import from old sdk so I am assuming you are are using an older version. In newer version @moralisweb3/evm-utils is replaced with @moralisweb3/common-evm-utils

Okay bro, Iā€™ll try it out now.
Iā€™ll get back to you

Thanks

1 Like

Bro, itā€™s didnā€™t work.
Same problem

defaultEvmApiChain is already registered