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);
};