[SOLVED] Getnfts limit of 100

Good day - is it compulsary to use pagination when the limit is in place? the issue is that I am filtering out all nfts owned by a user bar the 7 collections I want on my dapp meaning sometimes I have no nfts on page one… I know I need to somehow use a forloop to populate the array of nfts owned by the user but I am quite lost as to how to do this as I am unsure of where to put the var i in the

var nfts = await Moralis.Web3API.account.getNFTs(options);
var length = Math.ceil(nfts.total)
var talk =[...nfts]
for(let i = 0; i < length; i++) { talk.push(nfts(i).next())}  
//filtering the results by token_address
 let filteredNFTs = talk?.filter(
    (nftMetadata) =>
    nftMetadata?.token_address == (nfgs?.coll)?.toLowerCase() ||
    nftMetadata?.token_address == (nfgs?.bakc)?.toLowerCase() || 
    nftMetadata?.token_address == (nfgs?.swe)?.toLowerCase() ||
    nftMetadata?.token_address == (nfgs?.ssdf)?.toLowerCase() ||
    nftMetadata?.token_address == (nfgs?.fffe)?.toLowerCase()      
  );

Yes you will need to use pagination/cursor if you want to get the next page of results (if any).

There are examples here for using next().

There is also an example here of looping with cursor manually.

After adding this code I started to get rate limited and my site is no longer working - getting the ā€œapplication error: client sideā€¦ā€ error on both mobile alongside pc. I assume its because its due to pagination not being handled by a button on call however I paid for the most expensive server bundle so I do not see why I am being rate limited

const fetchNFTs = async () => {
    
  

  const options = {
    chain: "mainnet",
    address: id,
  };
  
  const fetchit = await Moralis.Web3API.account.getNFTs(options);
  setPage(fetchit)
  setPrevPage(fetchit)
  

}

useEffect(() => {
if (page && prevPage) {
    filtered()
}
}, [page, prevPage])


const filtered = async() =>{
  
 const length = Math.ceil((page?.total)/100)

  if(length>1){
  
    for(let i = 0; i < length; i++) { 
      var next = await page?.next()
      if(prevPage[1]){
        var hi = [...prevPage]
      }
      else{
        var hi = [prevPage]
      }
      setPrevPage([...hi, next])
    
      setPage(next)
     

    }

var len = prevPage.length
    console.log(len)
    var filteredNF = []
    
    
    
    for(let i =0; i<len; i++){
      var filtere = (prevPage[i].result)?.filter(
        (nftMetadata) =>
        nftMetadata?.token_address == (nfgs?.bayc)?.toLowerCase() ||
        nftMetadata?.token_address == (nfgs?.mayc)?.toLowerCase() || 
        nftMetadata?.token_address == (nfgs?.punk)?.toLowerCase() ||
        nftMetadata?.token_address == (nfgs?.dcl)?.toLowerCase() ||
        nftMetadata?.token_address == (nfgs?.otherside)?.toLowerCase()      
      );
       filteredNF.push(filtere)
    }
    var filteredNFTs= filteredNF.flat()
    console.log(filteredNFTs)
    
  }

you can try to add some delay, maybe before or after this call

I added delay as per the following however I still get the error below the example code shown below

I was under the impression that paying for the business package wouldn’t rate limit me especially since our usership is not high at all

const delay = ms => new Promise(res => setTimeout(res,ms))

const filterdon = async() =>{
 
 const length = Math.ceil((page?.total)/100)

  if(length>1){
  
    for(let i = 0; i < length; i++) { 
      await delay(500)
      if(page.cursor){
      var swag = await page?.next()
      if(prevPager[1]){
        var hi = [...prevPager]
      }
      else{
        var hi = [prevPager]
      }
      setPrevPage([...hi, swag])
    
      setPage(swag)
    }

    }  
   
    var len = prevPager.length
   
    var filteredNF = []
    
    
    
    for(let i =0; i<len; i++){
      var filtere = (prevPager[i].result)?.filter(
        (nftMetadata) =>
        nftMetadata?.token_address == (nfgs?.bayc)?.toLowerCase() ||
        nftMetadata?.token_address == (nfgs?.mayc)?.toLowerCase() || 
        nftMetadata?.token_address == (nfgs?.punk)?.toLowerCase() ||
        nftMetadata?.token_address == (nfgs?.dcl)?.toLowerCase() ||
        nftMetadata?.token_address == (nfgs?.otherside)?.toLowerCase()      
      );
       filteredNF.push(filtere)
    }
    var filteredNFTs= filteredNF.flat()
   
    
  }
  else{
    var nftBalance = page.result
    var filteredNFTs = nftBalance?.filter(
      (nftMetadata) =>
      nftMetadata?.token_address == (nfgs?.bayc)?.toLowerCase() ||
      nftMetadata?.token_address == (nfgs?.mayc)?.toLowerCase() || 
      nftMetadata?.token_address == (nfgs?.punk)?.toLowerCase() ||
      nftMetadata?.token_address == (nfgs?.dcl)?.toLowerCase() ||
      nftMetadata?.token_address == (nfgs?.otherside)?.toLowerCase()      
    );
  }
  
  setNftBalances(filteredNFTs);
}

error

Too many requests to Web3 API from this particular client, the clients needs to wait before sending more requests. This can be adjusted using Moralis.settings.setAPIRateLimit. Read More: https://docs.moralis.io/moralis-server/web3-sdk/rate-limit.
    at Function.<anonymous> (_app-22f4ferf55dc4b5c7.js:25:102360)

This is a rate limit from the server. You have to follow that link from that error message and you can update the limit for that server. You have to update the cloud code for the server with a new limit.

I see - is it still possible to update cloudfunctions on the moralis dashboard?

You have to use Moralis admin cli now

Thanks man - your help is always much appreciated

1 Like

This answer seems to elude to the limiting of a single user making too many requests per minute… However I have not used the site in a couple of hours and I still get the same console error after loading one page which only calls one moralis function in conjunction with a for loop with .next() and the delay as you advised

You can check your network requests in your browser. Check if any other code is using the API.

it depends on what delay you added, on how many calls were made, did you change those limits in cloud code?

Moralis.settings.setAPIRateLimit({
    anonymous:50, authenticated:100, windowMs:60000
  })

this is what I entered however I still get the error… Also when I log in to moralis and click cloudfunctions they do not turn up as they used to

This is the delay I added

Try different limits, like 100 requests per second

What you mean for them turning up?
Do you see the cloud code there?

No - I do not see the cloud code when I login to my moralis and click cloudcode

And the response is also not the same as in the tutorial - I get Listening folder: /cloudFunctions

You may have to change the command a little. Try to look at the parameters, you can provide a folder or a file. There are different parameters in that case. From that output it looks like it tries to sync a folder