How to get token price from a Polygon token?

So I’ve been creating a dex from this tutorial (https://www.youtube.com/watch?v=t8U7GRrlYW8) and I noticed that he uses ERC-20 tokens in the video, since they are added by default in the software.

However, how can I make it grab the token price from polygon?

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

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

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

  const {query} = req;

  const responseOne = await Moralis.EvmApi.token.getTokenPrice({
    address: 
  })

  const responseTwo = await Moralis.EvmApi.token.getTokenPrice({
    address: 
  })

  console.log(responseOne.raw);

  console.log(response.Two.raw);

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

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

I believe that I have to add something in here

  const responseOne = await Moralis.EvmApi.token.getTokenPrice({
    address: 
  })

  const responseTwo = await Moralis.EvmApi.token.getTokenPrice({
    address: 
  })

What do I need to do?

1 Like

Hi @obaming

You will have to mention that chain param with polygon chain Id in the getTokenPrice function.
Example:

 const responseOne = await Moralis.EvmApi.token.getTokenPrice({
    address: "",
    chain: "0x89"
  })
1 Like