I want to make it so that it lists out all of the NFTs for a particular contract. I already have the code to list all of the NFTs:
async function getNFTs(){
const options = { chain: 'matic' }
const nfts = await Moralis.Web3.getNFTs(options);
nfts.forEach(function(nft){
let url = fixURL(nft.token_uri);
fetch(url)
.then(response => response.json())
.then(data => {
$("#content").html($("#content").html()+"<h2>"+data.name+"</h2>");
});
})
}
function fixURL(url){
if(url.startsWith("ipfs")){
return "https://ipfs.moralis.io:2053/ipfs/"+url.split("ipfs://ipfs/").slice(-1)[0];
} else{
return url+"?format=json"
}
}
The code above works fine but this following code gives me this error
Uncaught (in promise) TypeError: nfts.forEach is not a function
at getNFTs:
async function getNFTs(){
const options = { chain: 'matic', token_address: "CONTRACTADDRESS" } //changed
const nfts = await Moralis.Web3API.account.getNFTsForContract(options); //changed
nfts.forEach(function(nft){
let url = fixURL(nft.token_uri);
fetch(url)
.then(response => response.json())
.then(data => {
$("#content").html($("#content").html()+"<h2>"+data.name+"</h2>");
});
})
}
function fixURL(url){
if(url.startsWith("ipfs")){
return "https://ipfs.moralis.io:2053/ipfs/"+url.split("ipfs://ipfs/").slice(-1)[0];
} else{
return url+"?format=json"
}
}