Hello
import Moralis from "moralis";
import { EvmChain } from "@moralisweb3/evm-utils";
export default async function handler(req, res) {
const chain = EvmChain.ETHEREUM;
await Moralis.start({ apiKey: process.env.MORALIS_API_KEY });
async function getNftMetaData(address, chain, tokenId) {
console.log("Address: ", tokenId);
const response = await Moralis.EvmApi.nft.getNFTTransfers({
address,
chain,
tokenId,
});
const priceInEth = (
Number(response.result[0].value) / 1000000000000000000000000000000000000
).toFixed(3);
if (priceInEth > 0) {
return { price: priceInEth };
} else return { price: null };
}
async function getAllNftMetaData() {}
const response = await Moralis.EvmApi.nft.getWalletNFTs({
address: req.body.user.address,
chain,
});
const newResult = await Promise.all(
response.data.result.map(async (nft) => {
const nftData = await getNftMetaData(
nft.token_address,
chain,
nft.token_id
);
return {
lastNftPrice: nftData,
...nft,
};
})
);
const newResponse = {
...response,
data: { ...response.data, result: [...newResult] },
};
res.status(200).json(newResponse);
}
Iβm trying to get all the nfts for an address (just the first page), then get the data for each of those nfts (to get the last price if any), in the end sending it all combined as a response, last 100 nfts list for a wallet including last price
The code works ok for a few nfts, but runs into a rate limit error after that
Any adivce?