This code is from the Ultimate NFt tutorial.
so you guy made a change to the initialize function and required use of the new syntax
Moralis.start({serverUrl:“https://vgyy4b11hszk.bigmoralis.com:2053/server”,
appId :“UkAR38SqWww25gkgwKdW2AC1nFG08kUWwzOQwE5C”});
And now i have to use this promise to get the Current user
Moralis.User.currentAsync().then(function(user)
my problem is that I dont know how to implement this syyntax and I guess the docs assume you should already know.
Moralis.start({serverUrl:"https://vgyy4b11hszk.bigmoralis.com:2053/server",
appId :"UkAR38SqWww25gkgwKdW2AC1nFG08kUWwzOQwE5C"});
// const CONTRACT_ADDRESS = "0xc1f5b3fe13906882c7c07142ca09727ec44a2c8a"; //cant use as a variable because the option wants a string
function fetchNFTMetadata(NFTs){
let promises = [];
for (let i = 0; i <NFTs.length; i++) {
let nft = NFTs[i];
let id = nft.token_id;
// call moralis cloud function -> static jason file
promises.push(fetch("https://vgyy4b11hszk.bigmoralis.com:2053/server/functions/getNFT?_ApplicationId=UkAR38SqWww25gkgwKdW2AC1nFG08kUWwzOQwE5C&nftId=" + id)
.then(res => res.json())
.then(res => JSON.parse(res.result))
.then(res => {nft.metadata= res})
.then(res => {
const options = { address: "0x1c304c9b9eb54c16d25855ad29252553cf521c0b", token_id: id, chain: "rinkeby" };
return Moralis.Web3API.token.getTokenIdOwners(options)
})
.then( (res) => {
nft.owners = [];
res.result.forEach(element => {
nft.owners.push(element.owner_of);
});
return nft;
})
// .then(() => {return nft;})
)}
return Promise.all(promises);
}
function renderInventory(NFTs){
const parent = document.getElementById("app");
for (let i = 0; i < NFTs.length; i++) {
const nft = NFTs[i];
console.log(nft)
let htmlString =`
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="${nft.metadata.image}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">${nft.metadata.name}</h5>
<p class="card-text">${nft.metadata.description}</p>
<p class="card-text">Amount: ${nft.amount}</p>
<p class="card-text">Number of owners: ${nft.owners.length}</p>
<a href="/mint.html?nftId=${nft.token_id}" class="btn btn-primary">Mint</a>
</div>
</div>
`
let col =document.createElement("div");
col.className= " col col-md-4"
col.innerHTML= htmlString;
parent.appendChild(col);
}
}
async function initializeApp() {
const options = { address: "0x1c304c9b9eb54c16d25855ad29252553cf521c0b", chain: "rinkeby" };
let NFTs = await Moralis.Web3API.token.getAllTokenIds(options);
let NFTWithMetadata = await fetchNFTMetadata(NFTs.result);
renderInventory(NFTWithMetadata);
}
initializeApp();