Closed EduardoMateos closed 2 years ago
Hey @EduardoMateos !
These are the cloud functions I got on Moralis.
`Moralis.Cloud.define("listedAndSoldNFTs", async (request) => { const query = new Moralis.Query("ListedNFTs"); query.descending("createdAt"); query.limit(10); const list = await query.find();
const query2 = new Moralis.Query("MintedNFTs"); query2.descending("createdAt"); let mints = await query2.find(); let listed = []; let sold = [];
for (let i = 0; i < list.length; i++) { if (list[i].attributes.Sold === 0) { for (let j = 0; j < mints.length; j++) { if (list[i].attributes.TokenID === mints[j].attributes.tokenId) { const nft = { tokenId: list[i].attributes.TokenID, price: list[i].attributes.Price.toString(), createdAt: list[i].attributes.createdAt, image: mints[j].attributes.image, name: mints[j].attributes.name } listed.push(nft) } } } }
for (let i = 0; i < list.length; i++) { if (list[i].attributes.Sold === 1) { for (let j = 0; j < mints.length; j++) { if (list[i].attributes.TokenID === mints[j].attributes.tokenId) { const nft = { tokenId: list[i].attributes.TokenID, price: list[i].attributes.Price.toString(), createdAt: list[i].attributes.createdAt, image: mints[j].attributes.image, name: mints[j].attributes.name } sold.push(nft) } } } }
return [listed, sold] });
Moralis.Cloud.define("createdNFTs", async (request) => { const query = new Moralis.Query("ListedNFTs"); query.descending("createdAt"); const list = await query.find();
const query2 = new Moralis.Query("MintedNFTs"); query2.descending("createdAt"); query2.equalTo("creator", request.params.acc) let mints = await query2.find(); let created = [];
for (let i = 0; i < mints.length; i++) { if (mints[i].attributes.creator === request.params.acc){ const nft = { tokenId: mints[i].attributes.tokenId, creator: mints[i].attributes.creator, price: undefined, createdAt: mints[i].attributes.createdAt, image: mints[i].attributes.image, name: mints[i].attributes.name } created.push(nft) for (let j = 0; j < list.length; j++){ if (created[created.length-1].tokenId === list[j].attributes.TokenID){ created[created.length-1].price = list[j].attributes.Price.toString() } } } }
return created });`
Using Moralis Cloud Functions to make the lists I use on feed, dashboard, index etc.
Hope this helps!
Thank you so much!
Hey !
@vaehaaland
Thanks for your work, it's incredible!
I have found your repository and I am working with it locally to fully understand how smart contracts and moralis work.
I see that you make calls to cloud function of moralis. Can you share the code of these functions?
thanks!
:)