Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
¿Cómo envolver una función asíncrona en un bucle o cómo ejecutar una función asíncrona en un bucle?

Esta es mi función:

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

He intentado ejecutarlo en un bucle:

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

Pero tiene un error en cada iteración:

 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 }

Pero si ejecuto la función una vez fuera de un ciclo, no tiene errores.

¿Cómo ejecutar esa función en un bucle o cómo envolver el código de función con un bucle?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!