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

155
Views
Cómo agregar llamadas de contrato web3js a Promise.all()

Trataré de explicar esto lo mejor que pueda porque no tengo mucha experiencia con Promise, en su mayoría solo usé async/await

Estoy construyendo una base de datos y tengo algo como esto

 let promises = [] for (let j = 0; j < batchSize; j++) { let token0Address = token0Addresses[j] let token0Contract = new web3.eth.Contract(abis.token, token0Address) promises.push(token0Contract.methods.name().call()) } try { let token0Names = await Promise.all(promises) } catch {other stuff}

El problema con el que me estoy encontrando es que algunos tokens no tienen nombres que esperaba que fueran capturados por el bloque try catch. Pero a veces las llamadas se devuelven antes de que llegue al bloque de prueba y arroja un error de todos modos.

También he probado algo como esto

 promises.push(() => token0Contract.methods.name().call())

pero esto solo hace que Promise.all (promises) devuelva un montón de funciones

yo también he intentado

 promises.push(new Promise(function(resolve, reject) { resolve(token0Contract.methods.symbol().call()) }))

y

 promises.push(new Promise(function(resolve, reject) { token0Contract.methods.name().call(function(error, result)) { if (error) { reject(error) } else { resolve(result) } } }))
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Descubrí una solución si alguien más alguna vez tiene este problema

 let tokenNameFunctions = [] for (let j = 0; j < batchSize; j++) { let token0Address = token0Addresses[j] let token0Contract = new web3.eth.Contract(abis.token, token0Address) token0NameFunctions.push(() => token0Contract.methods.name().call()) } let tokenNames = await Promise.allSettled(tokenNameFunctions.map(e => {return f()}))

No sé si esta es la mejor manera de manejar algo como esto, pero funciona de todos modos

about 4 years ago · Juan Pablo Isaza Report
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!