Hello,
I am trying to build a page where i can see my nft with one of the moralis youtube tutorial. But i am getting an error saying “Unexpected token } in JSON at position 224” when i am trying to console log my nfts with the metadata. Could you please tell me what mistake i am doing in this code?
//fetch nfts
function fetchNFTMetadata(NFTs) {
let promises = [];
for (let i = 0; i < NFTs.length; i++) {
let nft = NFTs[i];
let id = nft.token_id;
let hexId = parseInt(id).toString(16);
let paddedHex = ("0000000000000000000000000000000000000000000000000000000000000000" + hexId).slice(-64);
promises.push(fetch("https://mydomain/" + paddedHex + ".json")
.then(res => res.json())
.then(res => JSON.parse(res.result))
.then(res => { nft.metadata = res })
.then(() => { return nft; }))
}
return Promise.all(promises);
}
//sign in function
async function initializeApp() {
let currentUser = Moralis.User.current();
if (!currentUser) {
currentUser = await Moralis.Web3.authenticate();
}
// Get all nfts if user signed in
const options = {
address: "My Contract Adress",
chain: "bsc testnet",
};
let NFTs = await Moralis.Web3API.token.getAllTokenIds(options);
let NFTWithMetadata = await fetchNFTMetadata(NFTs.result);
console.log(NFTWithMetadata);
}
initializeApp();