1

I was fetching NFTs from certain contract for connected wallet using alchemy-sdk, and it was working fine, NFTs were retrieved and displayed on the frontend app.
But unfortunately this solution stopped working and I can't tell even from when.

This is my alchemy instance declared inside of a class and its settings:

const settings = {
  apiKey: process.env.POLYGON_API_KEY, 
  network: Network.MATIC_MAINNET
};

alchemy: Alchemy = new Alchemy(settings);

This is my backend service function where I'm calling the alchemy-sdk to get NFTs data:

async getAddressNfts(address: string): Promise<NFTsResponseInterface[]> {

    try {
      const response: OwnedNftsResponse = await this.alchemy.nft.getNftsForOwner(address, {
        contractAddresses: [collectionPolygonAddress]
      });
  
      const nftsResponse: NFTsResponseInterface[] = response.ownedNfts.map((item) => ({
        tokenId: item.tokenId,
        image: item.rawMetadata.image
      }));
  
      return nftsResponse;
      
    } catch (error) {
      console.log(error);
      return [];
    }
  }

And error that I'm getting is saying that I exceeded requests capacity. But I did not. enter image description here Alchemy dashboard is showing barely 30 requests (with automatic retries) after couple of tries: enter image description here enter image description here I also tried creating new api key, but with no luck.
I tried as well different settings, without specified api key, requesting to Alchemy default RPC, but it was throwing the same errors.

And just in case this is how I'm requesting to the backend for NFTs:

  const getNftsData = async () => {
    try {
      const { data } = await getNfts(connectedAccount);
      setAccountNFTs(data);
      
    } catch (error) {
      toast.error("Problem fetching your Crooked Snouts", { theme: "colored" });
    }
  }
  
  useEffect(() => {
    if(connectedAccount) {
      getNftsData();
    }
  }, [connectedAccount]);

Somebody can help with that? Or check if your applications with alchemy-sdk are working properly?\ Unfortunatelly on Alchemy discord nobody responds.

3 Answers 3

1

The error code 429 implies that Your app has exceeded its compute unit per second capacity. The requests, unfortunately, do not go through and as a result, the dashboard responses aren't returning the correct results.

Note, each call you make to get the NFTs for a particular connected address is logged as one response, this implies that in a situation where you have an address (EOA or Contract), with a collection of NFTs that exceeds the request per second limit, a 429 response is returned.

A possible way to solve this is to cache your requests, and/or limit the number of calls to the responses of an EOA to a certain number.

The error message is explicit as well. You can find a number of ways to solve this problem using this guide: https://docs.alchemy.com/reference/throughput

0

For some weird reason, while I was initializing settings object like this, to later on use it inside of my class:

const settings = {
  apiKey: process.env.POLYGON_API_KEY, // Replace with your Alchemy API key.
  network: Network.MATIC_MAINNET // Replace with your network.
};

@Injectable()
export class NftDataService {

  alchemy: Alchemy = new Alchemy(settings);
  // ....

}

At the point of assigning process.env.POLYGON_API_KEY variable was actually undefined. So with the requests alchemy instance was actually using default provider.

And that would explain why it was working at the beginning and later on it wasn't, maybe the limits were changed on the default provider, or there is way much more traffic right now.

So I deleted the setting object and I moved it directly to the initialization of alchemy instance like this:

@Injectable()
export class NftDataService {

  alchemy: Alchemy = new Alchemy({
    apiKey: process.env.POLYGON_API_KEY, // Replace with your Alchemy API key.
    network: Network.MATIC_MAINNET // Replace with your network.
  });

  // ....
}

And right here inside of my class process.env.POLYGON_API_KEY is actually what it was meant to be. So it's not on Alchemy side.

So the key takeaway here is to make sure if your API key is what you think it is.

0

I encountered the same error, In my case I am not accessing the env variable correctly so try to console.log(process.env.MY_API_KEY); make sure it is not undefined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.