[SOLVED] Code:141 error [object Object]

It seems overnight I have an issue. Iā€™ve had no issue with this Dapp for the past couple of weeks yesterday I was unable to retrieve any of the NFTs that the current user owns from my Dapp contract, now today I can no longer fetch those owned NFTs nor any NFTs within the contract. I have updated my server, Moralis SDK, and web 3 dist packages. to no avail, my next step will be to create a new server and try again but I donā€™t want to redeploy this contract which Iā€™m able to interact with fine. I did upgrade my server to proā€¦not sure if this may be causing the error. Console says itā€™s a Moralis error, I tried the solution that has worked for others, still not functioning properly. However, if I refresh a bunch of times sometimes My NFTs will appear.

my server: https://n9z8d6wmje7i.usemoralis.com:2053/server
appId: Rs074bIe78OjHjWuKC9qZFBM30hOHY4aGqu25vMN
contract: 0xe7430180aEC2d17EEbDb78a7aEeAF9C88312a573

using: [email protected] and [email protected]
Server: 0.0.281

javascript code where error appears:

async function getUserData(){
    let accounts = currentUser.get('accounts');
    const  options = {chain: 'mumbai', address: accounts[0], token_address: CONTRACT_ADDRESS};
    //return Moralis.Web3API.account.getNFTsForContract(options)
    return Moralis.Web3API.account.getNFTsForContract(options) 
    .then( (data) => { 
    let result = data.result.reduce( (object, currentElement) => {
              object[currentElement.token_id] = currentElement.amount;
              return object;
            }, {})

            return result;
    });
}


init = async () => {
    await Moralis.start({ serverUrl, appId });

    currentUser = await Moralis.User.current();
    wallet = currentUser;
    let ownedNFTs = [];
    
    //web3 = await Moralis.Web3.enable(); 
    web3 = await Moralis.enableWeb3(); 
    
    if(!currentUser){
        window.location.pathname = "./dist/beta.html"; 
    }

   
    const options = {address: CONTRACT_ADDRESS, chain: "mumbai"};
    let NFTs = await Moralis.Web3API.token.getNFTOwners(options);

    for(let i = 0; i < NFTs.result.length; i++){   
        if(NFTs.result[i].owner_of == wallet.attributes.accounts[0]){
            ownedNFTs.push(NFTs.result[i]);    
        }   
    }
   
    let userData = await getUserData();

    await getCollection(ownedNFTs, userData);
}
options = {address: "0xe7430180aEC2d17EEbDb78a7aEeAF9C88312a573", chain: "mumbai"};
NFTs = await Moralis.Web3API.token.getNFTOwners(options);

this code works fine for me in particular, I also tested it with your server

1 Like

I know itā€™s strange I havenā€™t had any issues up until now, and for some reason, It will function properly randomly, itā€™s a lot of work but do you recommend simply deleting and starting a new server, or is that a shot in the darkā€¦I Tried to swap your lines for mine (which are identical minus the variable lol) no luck

I donā€™t think that it is a problem related to your server, at least not at this moment, you can do more debugging to see what parameters you send to Moralis.Web3API functions when you get that error.

-_-

I just donā€™t get it, and I have a lot on the line. There has to be a better way than this. Thank you for your time.

I think that I got to a similar problem, where a specific call sometimes works sometimes doesnā€™t. It may be related.

1 Like

Yeah, we will figure it out eventually. Thank you for everything you guys have really been great and thats a serious under statement.

It may not be something on your side now, you could wait until tomorrow.

1 Like

it should work fine for you now

1 Like

lol it does thank you so much

hi CryptoKid and ibn5x,

How was this solved, I run into the same issue unfortunately after doing Philipā€™s tutorial.
My console gives the following error message:

main.js:13 GET https://4ā€¦w.usemoralis.com:2053/server/functions/getNFT?_ApplicationId=kā€¦H&nftId=1 400

{code: 141, error: ā€˜NFTid is not definedā€™}

  1. code: 141
  2. error: ā€œNFTid is not definedā€
  3. [[Prototype]]: Object

I used below code:

Moralis.start({ serverUrl : ā€œserverā€, appId : ā€œā€¦Hā€});

function fetchNFTMetadata(NFTs){
for (let i = 0; i < NFTs.length; i++){
let nft = NFTs[i];
let id = nft.token_id;
//Call Moralis Cloud function -> Static JSON file
fetch(ā€œhttps://4ā€¦w.usemoralis.com:2053/server/functions/getNFT?_ApplicationId=ā€¦H&nftId=ā€ + id )
.then(res => res.json())
.then(res => console.log(res))
}

}

async function init(){
let currentUser = Moralis.User.current();
if(!currentUser){
currentUser = await Moralis.Web3.authenticate();
}

const options = { address: "0x...c6", chain: "mumbai" };
NFTs = await Moralis.Web3API.token.getAllTokenIds(options);
fetchNFTMetadata(NFTs.result); 

}

init();

Thanks!

Arnoud

Hey @AJ10
Can you format your code?

A bit unreadable

Potential solution could be to declare let NFTid in your fetchNFTMetadata()

thank you for the quick reply. I tried to add let NFTid, but I either didnt do it right, or it doesnt solve it. :slight_smile:


Moralis.start({ serverUrl : ā€œserverā€, appId : ā€œā€¦Hā€});

function fetchNFTMetadata(NFTs){

for (let i = 0; i < NFTs.length; i++){

let nft = NFTs[i];

let id = nft.token_id;

//Call Moralis Cloud function -> Static JSON file

fetch(ā€œhttps://4ā€¦w.usemoralis.com:2053/server/functions/getNFT?_ApplicationId=ā€¦H&nftId=ā€ + id )

.then(res => res.json())

.then(res => console.log(res))

}

}

async function init(){

let currentUser = Moralis.User.current();

if(!currentUser){

currentUser = await Moralis.Web3.authenticate();

}

const options = { address: "0x...c6", chain: "mumbai" };

NFTs = await Moralis.Web3API.token.getAllTokenIds(options);

fetchNFTMetadata(NFTs.result);

}

init(); 

I hope the code is better readable like this, sorry, it's the first time I am active here.

Thanks!

Can you share your cloud function?

Moralis.Cloud.define("getNFT", async (request) => {
  const logger = Moralis.Cloud.getLogger()
  
  let NFTId = request.params.nftId;
  let hexId = parseInt(NFTid).toString(16);
  let paddedHex = ("0000000000000000000000000000000000000000000000000000000000000000" + hexId).slice(-64)
  logger.info(paddedHex);
  return Moralis.Cloud.httpRequest({url: "https://rhxqxoyuofhh.usemoralis.com/" + paddedHex +".json"})
  .then(function(httpResponse){
  	return httpResponse.text;
  })
        
})

Check the value of nftId
by using
console.log(request.params.nftId)

this gives the following:

VM470:1 Uncaught ReferenceError: request is not defined
    at <anonymous>:1:13

why arent you using?
Moralis.Cloud.run() to run cloud functions

From where you got to write this line?

can you access cloud function like this? Asking since i havenā€™t seen it like this

also the format of the above line is incorrect

fetch(ā€œhttps://4ā€¦w.usemoralis.com:2053/server/functions/getNFT?_ApplicationId=+"ā€¦H"+&nftId=ā€ + id )

you can add here some logging

you should use a syntax like logger.info(JSON.stringify(request))

you can also run that cloud function directly with Moralis.Cloud.run

2 Likes

Thank you for the input, I will work with it. need to run now, but will try later.

I just followed philips tutorial:

1hr14min approx.