Rarity Generator Undefined Metadata

I’m working on the Rarity Generator. I’ve been running it without the timer loop and limiting the page size for testing, also logging the data.

When I run main.js:

it stops loading metadata after 53 NFTs, 
then it returns 3 as "undefined",
loads the 57th set of traits correctly,
then returns the rest of the page (up to 500) as "undefined".

It’s very consistent and stops loading on the same sets of traits each time.

When I limit the page size to less than 53, the process completes and the data is loaded to the DB, as expected. Since they are loaded in order of rarity, there’s no way to pinpoint which NFT is the first “undefined”.

Looking through the NFTs that do make it into the DB, I can see that all of their Token IDs are from the last 100 minted.

I’ve checked the metadata for the last 100 minted, and there are no obvious issues. I’ve also looked at the NFTs in question on OpenSea and the Moralis Marketplace on my website, where they load correctly and display all traits.

Some of the last 100 NFTs in my collection have been manually resynced on Moralis, some haven’t. There doesn’t seem to be any correlation.

At this point, I’m pretty well stuck. Just wondering if anyone has encountered something of this nature?

Can u share any one of the NFT’s ID and token address which return as undefined.

There is no way to know which NFT would be 54,55, or 56 . . .

The contract is on Polygon @ 0x51790d397e3cc5f418635796e75c8b58ea113f3d/24997
One of the tokens being seen as “undefined” is Token ID 24997.

(Particularly odd, as the Moralis Marketplace implemented on my website has no issues with this token, or several others that the Rarity Generator apparently doesn’t recognize.)

metadata looks ok. Did u try to console.log at the line which is returning undefined?

I’m not sure I know how to do that, someone showed me how to log all the metadata.

This is the error:

TypeError: Cannot read properties of undefined (reading 'map')
    at generateRarity (C:\Users\egali\Desktop\NFTs\Rarity Ranking\Rarity-Ranking-NFT-main\generator\main.js:52:33)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Here is the line of code from main.js:

let nftTraits = metadata[j].map((e) => e.trait_type);

I’d be glad to log the data, just don’t know how to do it.

try to see the data console.log(metadata[j]); console.log(trait_type); before this line

Thank you for showing me the specifics.

Here’s what that looks like in context:

  for (let j = 0; j < metadata.length; j++) 
  console.log(metadata[j]); console.log(trait_type);
    let nftTraits = metadata[j].map((e) => e.trait_type);
    let nftValues = metadata[j].map((e) => e.value);

That returned the same listing of the data, with a different Error Type:

  { trait_type: 'Backgrounds', value: 'Yellow_Suite' },
  { trait_type: 'LRMHead', value: 'LRMHead_14' },
  { trait_type: 'LRMMouth', value: 'LRMMouth_02' },
  { trait_type: 'LRMEyes', value: 'LRMEyes_12' },
  { trait_type: 'LRMGlasses', value: 'LRMGlasses_05' }
ReferenceError: trait_type is not defined
    at generateRarity (C:\Users\egali\Desktop\NFTs\Rarity Ranking\Rarity-Ranking-NFT-main\generator\main.js:52:41)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)