Error using the Moralis.Web3API [Solved]


I created a node.js application where I am trying to fetch contractMetaData using the endpoint Moralis.Web3API.token.getTokenMetadata(contractAddress)

I am using the Moralis.Web3API for the first time so I must have done something wrong with setting it up.
I have created a server at I assume I need this to connect the node.js client to.

This is the complete code:

const  Moralis = require('moralis/node')
Moralis.initialize({Server Application ID})
Moralis.serverURL = {Server Url}
const tokenInfo = await Moralis.Web3API.token.getTokenMetadata("xyz")

I did not connect a wallet or anything because I don’t need that. I just want to ‘query’ the blockchain.

I get the following error:

        error = new _ParseError.default(errorJSON.code, errorJSON.error);

ParseError: [object Object]
    at handleError (/path/to/project/node_modules/moralis/lib/node/RESTController.js:420:17)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async main (/path/to/project/index.js:24:21) {
  code: 141

I did a little digging and found that the [object Object] is actually a string that is taken from the error response in RESTController.js:

const errorJSON = JSON.parse(response.responseText);
error = new _ParseError.default(errorJSON.code, errorJSON.error);

So there seems to be an issue with the json serialisation of the error response from the server. It is therefor difficult for me to see what is actually going wrong. I did not find any information about the meaning of code: 141 either.

This seems to happen with all API calls that I try. Does anybody have an idea what I am doing wrong? What am I missing?

Thanks for the help!

You can put your entire code with server application id and server url.
I would think that it is an initialisation problem, but not sure.
Also, you need a relatively new version of Moralis SDK for that API call to work.

This is my entire code:

(async function main() {
    const  Moralis = require('moralis/node')
    Moralis.serverURL = ""
    const contractAddress = "0xA7950CE1Fe4816ce3CFdC8747316087B97A32b5C"
    tokenInfo = await Moralis.Web3API.token.getTokenMetadata(contractAddress)

I am using the Moralis SDK version 0.041. This is the newest version.

In package.json:

"dependencies": {
  "moralis": "^0.0.41"

it looks like this works without errors:

    const options = { chain: "eth", addresses: ["0xA7950CE1Fe4816ce3CFdC8747316087B97A32b5C", ] };
    tokenInfo = await Moralis.Web3API.token.getTokenMetadata(options)

I don’t know the chain for that address.

1 Like

Yes it is working now! Thank’s for helping out :slight_smile: