1

Running into a problem attempting to test with hardhat by forking mainnet. I'm following the instructions here: https://hardhat.org/hardhat-network/docs/guides/forking-other-networks. I have a mainnet app configured in my Alchemy account and am using its API key. The problem I'm seeing is, when I run

npx hardhat node --fork https://eth-mainnet.g.alchemy.com/v2/[API_KEY]

(with a valid API key of course) it fails with:

Error HH604: Error running JSON-RPC server: Too Many Requests error received from eth-goerli.g.alchemy.com.

Looking at the app logs in the Alchemy dashboard, sure enough, there are tons of 429 errors associated with calls to eth_getTransactionCount. This is a brand new app I've created in Alchemy as well. I tried pinning to a specifick block as well but it didn't seem to make a difference.

Why am I getting rate-limited simply trying to start the hardhat node?

enter image description here

1
  • That is something you have to ask Alchemy customer support. I'd guess that hardhat is making too many queries, when alchemy returns errors it retries again so the problem increases.
    – Ismael
    Nov 20, 2022 at 17:19

2 Answers 2

0

A 429 error is a code that specifies that your app has exceeded its compute unit per second capacity (throughput). Throughput is a measure of the number of requests your application can send per second. It is often known as the applications "rate limit". If a large number of requests are sent at the same time, you may hit your throughput capacity.

See: https://docs.alchemy.com/reference/throughput

1
  • Thanks, I understand what a 429 error is. The question is, why am i get rate-limited just trying to start the hardhat node?
    – Madbreaks
    Nov 16, 2022 at 20:41
-1

429 error from a specific API change the API

  web3.eth.getTransactionCount(address, defaultBlock)
 .then((count) => {
console.log(`The transaction count for ${address} at ${defaultBlock} is 
${count}`);
 })
 .catch((error) => {
console.error(error);
  });
 const fetch = require('node-fetch');

  const url = 'https://example.com/api';
  const maxRetries = 3;
 let retries = 0;

 function fetchData() {
fetch(url)
.then(response => {
  if (response.status === 429 && retries < maxRetries) {
    const delay = 1000 * (2 ** retries);
    retries++;
    setTimeout(fetchData, delay);
  } else if (response.ok) {
    return response.json();
  } else {
    throw new Error('Error fetching data');
  }
   })
  .then(data => {
  console.log(data);
  })
  .catch(error => {
  console.error(error);
});
}

fetchData();
  function sendRequest(url, retries = 0) {
    return new Promise((resolve, reject) => {
   request(url, (error, response, body) => {
      if (error) {
      if (retries < maxRetries && response.statusCode === 429) {
      const delay = 2 ** retries * 1000; // Exponential backoff delay
      setTimeout(() => {
        sendRequest(url, retries + 1)
          .then(resolve)
          .catch(reject);
         }, delay);
        } else {
         reject(error);

Your Answer

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

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