Parse API connection error

with exact server url and app id works on your PC?

how do you send the code on the server, is the code identical?

With the exact server url and app id yes, I’ve zipped the code -> uploaded to the server -> unzipped the code

maybe you can try to run a simple js script on the server manually to see how it works, it looks like there is some kind of server running there in js when it doesn’t work

Sorry what do you exactly mean with this?

from the initial image, it looks like something more complex than a script with 10 lines of code that runs

So I’ve made like a simple 1 function test code and it returned to owner of the nft inserted (this is the right id) but a bit later it gave the error again, so is it maybe like an error that it’s trying to connect a lot which causes it to error?

it looks like a different type of issue now, maybe you can add more debugging with console.log to see how many times it is called

Well it’s weird because it’s only fired once atm and it prints like something infront of the “Moralis.start” and it takes like 5-10 seconds but in the mean time it can do the functions.

So what do you think that the problem could be @cryptokid?

I don’t know exactly, I don’t have enough information

try to add some debugging, run a simpler script

I mean it’s just 1 function and it’s still getting the error

const express = require("express");
const Moralis = require('moralis/node');
var Web3 = require('web3');


const app = express();

const { MANAGER } = require("./config/smartcontracts.config");
const { managerABI } = require("./abis/manager");
// Initizalise
async function initMoralis(){
    const start = await Moralis.start({ serverUrl: "", appId: "" }).catch((err) => { console.log(err) });
    console.log(Moralis.CoreManager.get("VERSION"))
}

initMoralis();

async function getNFTOwner(){
    const address = '0x8bac6324c21b3db9d385a9172cea41ff36669f41'
    const tokenId = 1
	const endPoint = '';
	const provider = new Web3.providers.HttpProvider(endPoint);
	web3 = new Web3(provider);

	contract = new web3.eth.Contract(managerABI, MANAGER)
	const owner = await contract.methods.getTokenOwner(address, tokenId).call().catch((err) => { console.log(err) });
	
	console.log(owner)
}

// Repeat get all items every x minutes
setInterval(getNFTOwner, 1000); // 60.000 is 1 minute.

  

// Start server
app.listen(4000, () => {
 	console.log("API has been started on port 4000!");
})

try to use await here maybe

where was the endpoint initialized?

in particular this code doesn’t need moralis, as it doesn’t use any feature from it like web3api

If you would want to do that it should be done in the listen I think
like this:


// Start server
app.listen(4000, async() => {
    await initMoralis()
 	console.log("API has been started on port 4000!");
})

But that still gives the same error

The endpoint is initialised above it, but this is an endpoint from moralis as well

you mean that you hardcoded a speedy node url as that endPoint?

yes, indeed. Is that something that you shouldn’t do?

that is fine, it looks like you don’t use Moralis SDK in that code, in this case you don’t even need to init it

Oh yeah ofcourse, but like for other codes that I need it doesn’t work like for example:

const express = require("express");
const Moralis = require('moralis/node');
var Web3 = require('web3');


const app = express();

const { MANAGER } = require("./config/smartcontracts.config");
const { managerABI } = require("./abis/manager");
// Initizalise
async function initMoralis(){
    const start = await Moralis.start({ serverUrl: "https://rmatpmaksrdg.usemoralis.com:2053/server", appId: "dPGQ7D2JsTCoKnL98tLnLxWwewVjrJHSWD5AfeVi" }).catch((err) => { console.log(err) });
    console.log(Moralis.CoreManager.get("VERSION"))
}

initMoralis()

async function getAllTokenIds(){
	const tokens = await Moralis.Web3API.token.getAllTokenIds({ address: "0x8bac6324c21b3db9d385a9172cea41ff36669f41", chain: "rinkeby", }).catch((err) => { /*console.log(err)*/ });
	
	if(tokens){
	    return tokens
	} else {
	    return null
	}
}

// Repeat get all items every x minutes
setInterval(getAllTokenIds, 1000); // 60.000 is 1 minute.

  

// Start server
app.listen(4000, async() => {
 	console.log("API has been started on port 4000!");
})

add some logging to understand what happens there

use await for that initMoralis

try to write a simpler script that only calls a function