Rarity-Ranking-NFT icon indicating copy to clipboard operation
Rarity-Ranking-NFT copied to clipboard

Cannot read properties of null (reading 'attributes')

Open coffeeclubnfts opened this issue 2 years ago • 9 comments

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 avatar Mar 18 '22 18:03 coffeeclubnfts

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

coffeeclubnfts avatar Mar 18 '22 18:03 coffeeclubnfts

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

boshjerns avatar Mar 20 '22 12:03 boshjerns

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

JVmano avatar Mar 25 '22 17:03 JVmano

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

where do you toss that in

boshjerns avatar Apr 13 '22 12:04 boshjerns

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); }

raddad88 avatar Apr 13 '22 12:04 raddad88

what lines do you add that to/ replace

boshjerns avatar Apr 13 '22 12:04 boshjerns

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); }

raddad88 avatar Apr 13 '22 12:04 raddad88

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

boshjerns avatar Apr 13 '22 12:04 boshjerns

where is this?

raddad88 avatar Apr 13 '22 13:04 raddad88