[SOLVED] useSetIpfsUploadFolder.ts:111 errorIPFS Moralis SDK Core Error: [C0006] Request failed, (429): Rate limit exceeded

Hi, I’m trying to use ipfs and it gives me an error:

errorIPFS Moralis SDK Core Error: [C0006] Request failed, (429): Rate limit exceeded.

RATE_LIMIT_TTL = 30
RATE_LIMIT_AUTHENTICATED = 50
RATE_LIMIT_ANONYMOUS = 20

add : app.use(express.json({ limit: '50mb' }));
I modify the varoles, and in the same way it gives me the error.

frontend:
useSetIpfsUploadFolder:


import Moralis from 'moralis';

const readAsBase64 = (file: any) => {

  return new Promise((resolve, reject) => {

    const reader = new FileReader();

    reader.onload = () => {

      const result = reader.result;

      if (typeof result === 'string') {

        const base64Data = result.split(",")[1];

        resolve(base64Data);

      } else {

        reject(new Error("Error al leer el archivo."));

      }

    };

    reader.onerror = () => {

      reject(new Error("Error al leer el archivo."));

    };

    reader.readAsDataURL(file);

  });

};

const removeBaseUrl = (url: string) => {

  const baseUrl = 'https://ipfs.moralis.io:2053/ipfs/';

  return url.replace(new RegExp(`^${baseUrl}`), '');

};

const useSetIpfsUploadFolder = async (ethAddress: any, content: any, contentName: string, ifNft: boolean) => {

  console.log("ethAddressIPFS", ethAddress)

  console.log("contentIPFS", content)

  console.log("contentNameIPFS", contentName)

  try{

    if(ifNft){

     const abi: any  = [

        {

            path: contentName,

            content: {

              name: content.name,

              description: content.description,

              image: content.image,

              attributes: [

                {

                  "trait_type": "energy",

                  value: content.energy

                },

                {

                  "trait_type": "force",

                  value: content.force

                },

                {

                  "trait_type": "impact",

                  value: content.impact

                },

                {

                  "trait_type": "sustainability",

                  value: content.sustainability

                },

                {

                  "trait_type": "value",

                  value: content.valueNft

                },

                {

                  "trait_type": "rarity",

                  value: content.rarity

                },

                {

                  "trait_type": "type",

                  value: content.type

                },

              ]

            },

        },

      ];

      const response = await Moralis.EvmApi.ipfs.uploadFolder({ abi });

     

      console.log('responseUrlIpf', response);

      const responseUrl = response.raw

      const path = responseUrl[0].path

      const hash = removeBaseUrl(path);

      return { path, hash}

    }else{

      const base64Data = await readAsBase64(content)  as string;

      const fileUpload = [

        {

          path: `${ethAddress}/${contentName}`,

          content: base64Data.toString()

        }

      ]

      const response = await Moralis.EvmApi.ipfs.uploadFolder({

        abi: fileUpload

      });

      const responseUrl = response.raw

      const path = responseUrl[0].path

      const hash = removeBaseUrl(path);

      console.log('responseUrl :', responseUrl);

      return { path, hash}

    }

  }catch(error: any){

    console.error("errorIPFS", error)

  }

}

export default useSetIpfsUploadFolder;

handleClick function:

const handleClick = async () => {

    setLoading(true);

    for (let i = 0; i < files.length; i++) {

      const file: any = files[i];

      const { path, hash } = await useSetIpfsUploadFolder(

        collectionAddress,

        file,

        file.name,

        true

      );

      const imageFilePath = path;

      const imageFileHash = hash;

 

      try {

        const TokenIdHistory = Moralis.Object.extend('tokenIdHistory');

        const tokenIdHistory = new TokenIdHistory();

        tokenIdHistory.set('tokenId', 'YOUR_TOKEN_ID_HERE');

        tokenIdHistory.set('name', file.name);

        tokenIdHistory.set('type', file.type);

        tokenIdHistory.set('size', file.size);

        tokenIdHistory.set('ipfs', imageFileHash);

 

        tokenIdHistory.set("ownerAddress", ownerAddress.toLowerCase());

        tokenIdHistory.set("collectionAddress", collectionAddress.toLowerCase());

        tokenIdHistory.set("imageFilePath", imageFilePath);

        tokenIdHistory.set("imageFileHash", imageFileHash);

        tokenIdHistory.set("contractType", "ERC-721");

        tokenIdHistory.set("royalties", 20);

        tokenIdHistory.set("type", "image");

         

        await tokenIdHistory.save();

        console.log('Token ID saved to tokenIdHistory table');

      } catch (error) {

        console.error(error);

        setLoading(false);

        return;

      }

 

      // Calculate percentage of completion

      const progress = ((i + 1) / files.length) * 100;

      setProgress(progress);

    }

 

    setLoading(false);

    setProgress(0);

  };

Hey @davidzuccarini,

That error usually means that you are calling too much of Moralis API from our end and the rate limit on the server will not do much about it.

Can you check how much CU have you consumed for the last 24 hours? If you are under the free plan, then you’ll only have 4000 CUs per day

I did not exceed the limit if i need, make api calls? will this block me? since it will be needed approximately in this project. upload to ipfs in groups of 100 thousand nft. So this will be an impediment?
2023-06-04_21h32_56

Hey @davidzuccarini,

As long as you stay below 4000 CU that should be sufficient. However, if it’s not the amount of CU consumed, then it is likely because you are calling the IPFS API too frequently, you can try by adding a delay between calls so not to call the more API/s then what is allowed.

But if I do this, imagine the time it would take to mine 100,000 nft, they are approximately a million nft in total, it doesn’t make sense if it’s a tool. i can do it and I will delay… there is no solution for this?

If you need to do more API call, then your solution for this will be to upgrade your plan to a paid plan.

This is a limitation of the free plan since it’s mostly designed not to accommodate large amount of API calls as it is expected only for testing purposes.

vale. la api paga no tiene limite perfecto. si anteriormente se pagaba pero no se ha pagado por que no se ha podido salir a produccion. migrando todo al servidor propio. gracias por aclararlo. moralis siempre me responde y me ha ayudado. podrian darme soporte en esta pregunta por favor: https://forum.moralis.io/t/c0006-unauthorized-and-c0005-request-contains-unknown-parameter-network/23703/27

Hey there,

No problem! Let me take a look into that post~

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.