Keep throwing an exception: = new _ParseError.default(errorJSON.code, errorJSON.error);

I tried a ton of different ways, also suggested in other topics, I tried to simply fetch the token price of a contract address, but I get an error of json parsing.

Here is my code:

const Moralis  = require('moralis/node');

Moralis.initialize("LpEXpjpFgexv51r2nGym46XAdmMf8WeSJLqxEDj4");

Moralis.serverURL = "https://6kfhdlrelof3.moralishost.com:2053/server"

const options = {
    chain: "eth",
    address: "0x095418A82BC2439703b69fbE1210824F2247D77c"
};
const price = Moralis.Web3API.token.getTokenPrice(options);

What I tried:

1 I used only the first 3 rows (initialization), and the code doesn’t raise an error, just exits with code 0.
2 I put the code into a function like in other examples (so that I could use the async/await structure), but didn’t work
3 I tried other sdk commands, but same results :frowning:

What am I doing wrong?

Thank you for the help in advance :slight_smile:

1 Like

I got this working with my server, but not with yours:

x = async () => {
    const  Moralis = require('moralis/node')
    Moralis.initialize("TAXZpkfV4FbCnoY592sUJuCXak26hdgBxUz5oqqU")
    Moralis.serverURL = "https://mtpbh2zhvqjd.moralis.io:2053/server"

    price = await Moralis.Web3API.token.getTokenPrice(
        {address: "0xe9e7cea3dedca5984780bafc599bd69add087d56", chain: "bsc"})
    console.log(price)
    }

x();

you may need to go to https://admin.moralis.io/web3Api and try there a simple api and then maybe it would work for you too in case that you didn’t have an api key generated

oh I see, I used a local devchain server (no mainnet, no testnet) on Ganache environment. Could that be the issue?
Sorry if it’s a newbie question :confused:

that shouldn’t be the problem in this particular case, as you specify the chain explicitly to that api call

works with dev server too, tested now

so I went to test the API on moralis doc page,

I tested the GET erc20/{address}/price:

  • selected bsc
  • input https://6kfhdlrelof3.moralishost.com:2053/server as provider URL
  • input 0xe9e7cea3dedca5984780bafc599bd69add087d56 as address

I got a 401:

{
  "message": "API KEY missing from x-api-key header"
}

you don’t have to use provider URL there, but you may get same error with missing API KEY

1 Like

I updated the server and restarted it. Now it works :smiley: :smiley: :smiley:

Thank you for the help :slight_smile:

1 Like