Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

100
Vistas
How to wrap an async function in a loop or How to run an async function in a loop?

This is my function:

async function mintNFT(tokenURI) {
  const nonce = await web3.eth.getTransactionCount(PUBLIC_KEY, "latest"); //get latest nonce
  //the transaction
  const tx = {
    from: PUBLIC_KEY,
    to: contractAddress,
    nonce: nonce,
    gas: 500000,
    data: nftContract.methods.mintNFT(PUBLIC_KEY, tokenURI).encodeABI(),
  };
  const signPromise = web3.eth.accounts.signTransaction(tx, PRIVATE_KEY);
  signPromise
    .then((signedTx) => {
      web3.eth.sendSignedTransaction(
        signedTx.rawTransaction,
        function (err, hash) {
          console.log(
            "The hash of your transaction is: ",
            hash,
            "\nCheck Alchemy's Mempool to view the status of your transaction!"
          );
          if (!err) {
          } else {
            console.log(
              "Something went wrong when submitting your transaction:",
              err
            );
          }
        }
      );
    })
    .catch((err) => {
      console.log("Promise failed:", err);
    });
}

I have tried run it in a loop:

for (let i = 0; i < 10000; i++) {
  mintNFT("https://ipfs.io/ipfs/cid/" + i);
}

But it has error every iteration:

Something went wrong when submitting your transaction: Error: Returned error: replacement transaction underpriced
    at Object.ErrorResponse (/home/user/Projects/contract/node_modules/web3-core-helpers/lib/errors.js:28:19)
    at /home/user/Projects/contract/node_modules/web3-core-requestmanager/lib/index.js:302:36
    at /home/user/Projects/contract/node_modules/@alch/alchemy-web3/dist/cjs/util/promises.js:28:9
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  data: null
}

But if i run function one time outside a loop, it has no errors.

How to run that function in a loop or how to wrap function code with loop?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda