[SOLVED] Build A Web3 DEX | FULL COURSE | React, Node, Moralis, 1Inch

I’m trying to run code from Youtube video Build A Web3 DEX | FULL COURSE | React, Node, Moralis, 1Inch but it is giving the following error.

MoralisError [Moralis SDK Core Error]: [C0005] Invalid address provided

at new Promise () {
isMoralisError: true,
code: ‘C0005’,
details: undefined,
[cause]: undefined

2 Likes

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: query.addressOne

})

const responseTwo = await Moralis.EvmApi.token.getTokenPrice({

address: query.addressTwo

})

const usdPrices = {

tokenOne: responseOne.raw.usdPrice,

tokenTwo: responseTwo.raw.usdPrice,

ratio: responseOne.raw.usdPrice/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`);

});

});

1 Like

C:\dexStarter\dexBack\node_modules@moralisweb3\common-evm-utils\lib\dataTypes\EvmAddress\EvmAddress.js:50
throw new common_core_1.CoreError({
^

MoralisError [Moralis SDK Core Error]: [C0005] Invalid address provided
at EvmAddress.parse (C:\dexStarter\dexBack\node_modules@moralisweb3\common-evm-utils\lib\dataTypes\EvmAddress\EvmAddress.js:50:19)
at new EvmAddress (C:\dexStarter\dexBack\node_modules@moralisweb3\common-evm-utils\lib\dataTypes\EvmAddress\EvmAddress.js:18:34)
at EvmAddress.create (C:\dexStarter\dexBack\node_modules@moralisweb3\common-evm-utils\lib\dataTypes\EvmAddress\EvmAddress.js:46:16)
at Object.getRequestUrlParams (C:\dexStarter\dexBack\node_modules@moralisweb3\common-evm-utils\lib\operations\token\getTokenPriceOperation.js:38:41)
at OperationRequestBuilder.prepareUrl (C:\dexStarter\dexBack\node_modules@moralisweb3\api-utils\lib\resolvers2\OperationRequestBuilder.js:15:40)
at OperationResolver. (C:\dexStarter\dexBack\node_modules@moralisweb3\api-utils\lib\resolvers2\OperationResolver.js:58:50)
at step (C:\dexStarter\dexBack\node_modules@moralisweb3\api-utils\lib\resolvers2\OperationResolver.js:33:23)
at Object.next (C:\dexStarter\dexBack\node_modules@moralisweb3\api-utils\lib\resolvers2\OperationResolver.js:14:53)
at C:\dexStarter\dexBack\node_modules@moralisweb3\api-utils\lib\resolvers2\OperationResolver.js:8:71
at new Promise () {
isMoralisError: true,
code: ‘C0005’,
details: undefined,
[cause]: undefined
}

1 Like

Hi @Lzippel

Can you share how does your request URL looks like?
Since the address is read from the req URL query, If the query is not added to the request URL then the address would be undefined

const {query} = req;

Now I understand what I did wrong. It worked

http://localhost:3001/tokenPrice?addressOne=0xd533a949740bb3306d119cc777fa900ba034cd52&addressTwo=0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2

2 Likes