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

164
Vistas
How to add web3js contract calls to Promise.all()

Ill try to explain this the best I can because I haven't got much experience with Promise, mostly just used async/await

Im building a database and have something like this

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}

The issue im running into is that some tokens don't have names which I was hoping would be caught by the try catch block. But sometimes the calls are returned before it reaches the try block and throws an error anyway.

I've also tried something like this

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

but this just makes Promise.all(promises) return a bunch of functions

I've also tried

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

and

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 Respuestas
Responde la pregunta

0

Figured out a solution if anyone else ever has this issue

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

Don't know if this is the best way to handle something like this but works nonetheless

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