IAmJaysWay / Rarity-Ranking-NFT

Moralis Project
93 stars 80 forks source link

Cannot read properties of null (reading 'attributes') #11

Open coffeeclubnfts opened 2 years ago

coffeeclubnfts commented 2 years ago

TypeError: Cannot read properties of null (reading 'attributes') at /Users/timemachine/Downloads/Rarity-Ranking-NFT-main/generator/main.js:38:59 at Array.map (<anonymous>) at generateRarity (/Users/timemachine/Downloads/Rarity-Ranking-NFT-main/generator/main.js:38:26)

I keep getting this error when trying to run the rarity generator.

I tried the repo and watching the tutorial video, ended up with the same problem each time.

Any ideas?
coffeeclubnfts commented 2 years ago

It works totally fine when testing with the BAYC collection + metadata, wondering if it's something to do with my tokens starting at 1 and not 0? Any way to fix this?

The contract address I'm trying to generate rarity for is: https://etherscan.io/address/0x68bf5b45eb1851ed543c757c8dbef352be570cb7#code

boshjerns commented 2 years ago

i am stuck here as well - I hope moralis reaches out about this

JVmano commented 2 years ago

Apparently some collections cause this issue on Moralis like Invisible Friends, Cryptopunks V3, Pepe Universe and some others.

boshjerns commented 2 years ago

let metadata = allNFTs.map((e) => {console.log(JSON.parse(e.metadata).attributes)});

where do you toss that in

raddad88 commented 2 years ago

sorry, use this instead

let collection = allNFTs.map(e => { return { metadata: JSON.parse(e.metadata), token_id: e.token_id }; });

let metadata = collection.map(e => e.metadata); console.log(metadata.length);

for (let i = 0; i < metadata.length; i++) { console.log(metadata[i]?.attributes, i); }

boshjerns commented 2 years ago

what lines do you add that to/ replace

raddad88 commented 2 years ago

you would replace the line with

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

with

let collection = allNFTs.map(e => { return { metadata: JSON.parse(e.metadata), token_id: e.token_id }; });

let metadata = collection.map(e => e.metadata); console.log(metadata.length);

for (let i = 0; i < metadata.length; i++) { console.log(metadata[i]?.attributes, i); }

boshjerns commented 2 years ago

running into this now:

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

TypeError: metadata[i].map is not a function

appreciate your help a ton

raddad88 commented 2 years ago

where is this?