Cannot read properties of null (reading 'attributes')
coffeeclubnfts opened this issue · 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?
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
i am stuck here as well - I hope moralis reaches out about this
Apparently some collections cause this issue on Moralis like Invisible Friends, Cryptopunks V3, Pepe Universe and some others.
let metadata = allNFTs.map((e) => {console.log(JSON.parse(e.metadata).attributes)});
where do you toss that in
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);
}
what lines do you add that to/ replace
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);
}
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
where is this?