IAmJaysWay / dexFinal

56 stars 68 forks source link

could not fetch TokenPricedata using API #1

Open yuvedha-21 opened 1 year ago

yuvedha-21 commented 1 year ago

I've been following the youtube tutorial and got stuck when implementing backend token price data in the console. I could not find what I did wrong.Do tell me what I need to change.

const express = require("express");
const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/evm-utils");
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: query.addressOne,
  });

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

  console.log(responseOne.raw);
  console.log(responseTwo.raw);

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

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

// const runApp = async () => {
//   await Moralis.start({
//     apiKey: process.env.MORALIS_KEY,
//     // ...and any other configuration
//   });

//   const address = "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599";

//   const chain = EvmChain.ETHEREUM;

//   const response = await Moralis.EvmApi.token.getTokenPrice({
//     address,
//     chain,
//   });

//   console.log(response.toJSON());
// };

// runApp();
Neronumis commented 1 year ago

Same here, do you find a solution?

mrwinter09 commented 1 year ago

did anyone get some answers??

DylanBlockchainDev commented 7 months ago

has anyone found the solution? please help.

odin-hoang commented 6 months ago

Just remove the dot "." before /tokenPrice in app.get("./tokenPrice", async (req, res). Check carefully the query parameters of your request, for example http://localhost:3000/tokenPrice?addressOne=0x123&addressTwo=0x345

Abhrajitdas02 commented 3 months ago

are there any more bugs in the project?