I am getting rate limit issues while Fetching metadata info from smart contract using provider for Listed NFT’s and collections for nft marketplace site
Access to fetch at 'https://testnet.fuel.network/v1/graphql' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.Understand this error
helperFn.js:54
POST https://testnet.fuel.network/v1/graphql net::ERR_FAILED 429 (Too Many Requests)
I am fetching name, symbol , metadata for each collection and NFT’s listed
Can you please share the code for the request you are querying? also, what are the versions you are using?
"@fuel-wallet/sdk": "^0.16.0",
"@fuels/assets": "^0.20.0",
"@fuels/connectors": "^0.29.2",
"@fuels/react": "^0.29.2",
"fuels": "^0.94.8",
- I am calling this functions for each NFT collection
export async function fetchContractMetaDataWithFirstNFt(nftAddress, type) {
const provider = await Provider.create(blockchain["fuel_testnet"].publicRpc);
const asset = getMintedAssetId(nftAddress,"0x0000000000000000000000000000000000000000000000000000000000000000")
if (type === NFTStandardOutput.NFT) {
const contract = new NonFungibleCreator(nftAddress, provider);
const name = await contract.functions.name({bits: asset}).get();
const symbol = await contract.functions.symbol({bits: asset}).get();
const metaData = await contract.functions.metadata({bits: asset}, "URI").get();
const response = await fetch(metaData.value.String);
const responseData = await response.json();
return {
contractName: name.value.toString(),
contractSymbol: symbol.value.toString(),
img: responseData.image
}
}
if (type === NFTStandardOutput.SEMI_FT) {
const contract = new SemiFungibleCreator(nftAddress, provider);
const name = await contract.functions.name({bits: asset}).get();
const symbol = await contract.functions.symbol({bits: asset}).get();
const metaData = await contract.functions.metadata({bits: asset}, "URI").get();
const response = await fetch(metaData.value.String);
const responseData = await response.json();
return {
contractName: name.value.toString(),
contractSymbol: symbol.value.toString(),
img: responseData.image
}
}
}
- I am calling this function for each NFT listed in Marketplace
export const getNftMetadata = async(
nft_contract,
asset_id,
standard
) => {
try {
const provider = await Provider.create(blockchain["fuel_testnet"].publicRpc);
const assetIdInput = {
bits: asset_id
}
let metadataUrl;
if (standard == NFTStandardOutput.NFT) {
const contract = new NonFungibleCreator(nft_contract, provider);
const metadata = await contract.functions.metadata(assetIdInput, "URI").get();
console.log("metadata", metadata.value);
metadataUrl = metadata.value.String;
}else {
const contract = new SemiFungibleCreator(nft_contract, provider);
const metadata = await contract.functions.metadata(assetIdInput, "URI").get();
console.log("metadata", metadata.value);
metadataUrl = metadata.value.String;
}
try {
const response = await fetch(metadataUrl);
if (!response.ok) {
throw new Error("Network Error: Failed to fetch metadata.");
}
const metadata = await response.json();
console.log(metadata);
return metadata;
} catch (error) {
console.error("Error fetching metadata: ", error);
return null;
}
} catch (e) {
console.log("Error in listing asset", e.message);
// Add error toast here
return null;
}
}
Can the rate limit be increased ?
Is this on the frontend or the server side? Because our rate limit is already pretty generous. So I could only picture it being a real issue if they were proxying requests for a bunch of users from the same IP.