Rarity-Ranking-NFT Error

Hello,

I have followed the youtube video: https://www.youtube.com/watch?v=TXpfRRHwjak

and have cloned the repo: https://github.com/IAmJaysWay/Rarity-Ranking-NFT

When I am running /main/generator/main.js for a new nft collection to calculate rarity, I am getting the error below:

TypeError: Cannot read property ‘attributes’ of null
at C:\Code\rarity-ranking-nft\generator\main.js:39:59
at Array.map ()
at generateRarity (C:\Code\rarity-ranking-nft\generator\main.js:39:26)

This happened on a few collections, but here is a one of the contracts I used as an example: 0x75e95ba5997eb235f40ecf8347cdb11f18ff640b

Is there some workaround code that I can add to fix this?

it looks like this is the line with that error:

  let metadata = allNFTs.map((e) => JSON.parse(e.metadata).attributes);

maybe there are some token ids that don’t have metadata and maybe that is why it gives that error

Yes, this is common and shouldn’t cause it to break the code. I want to know if there is a workaround that I can add to avoid this from breaking the code.

I guess that you could modify some lines of code there to handle that case

I ran into the same problem.

   {
      token_address: '0x6632a9d63e142f17a668064d41a21193b49b41a0',
      token_id: '7879',
      amount: '1',
      contract_type: 'ERC721',
      name: 'Prime Ape Planet',
      symbol: 'PAP',
      token_uri: 'https://primeapeplanet.com/metadata/7879',
      metadata: '{"name":"Prime Ape #7879","description":"A unique collection of 7,979 3D hand-drawn Prime Apes, stored on the Ethereum network.","image":"https://primeapeplanet.com/images/prereveal.png","externalUrl":"https://primeapeplanet.com"}',
      synced_at: '2021-12-28T17:38:03.162Z'
    },
    ... 400 more items
  ]
}
7998
500
here
TypeError: Cannot read property 'attributes' of null
    at /home/amer/ethereum/dapp_marketplace/generator/main.js:42:59
    at Array.map (<anonymous>)
    at generateRarity (/home/amer/ethereum/dapp_marketplace/generator/main.js:42:26)

when i check the token_uri I can see the attributes are in the metadata


{
  "description": "A unique collection of 7,979 3D hand-drawn Prime Apes, stored on the Ethereum network.",
  "external_url": "https://primeapeplanet.com",
  "image": "https://primeapeplanet.com/images/7879.png",
  "name": "#7879",
  "attributes": [
    {
      "trait_type": "Clothing",
      "value": "T-Shirt camouflage"
    },
    {
      "trait_type": "Emotion",
      "value": "Seducing"
    },
    {
      "trait_type": "Eyes",
      "value": "Brown"
    },
    {
      "trait_type": "Skin",
      "value": "Light Brown"
    },
    {
      "trait_type": "Hat",
      "value": "Beanie Black"
    }
  ]
}

is this an issue with the moralis data or do I need to code around this?