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

189
Vistas
How to write array data to json?

How to write the data that the loop passes to the array "eventsPolygon", to json. This array returns 4 args. With this method, I get the error "TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined"

async function main() {
  console.log("Start checking rewards")
  const currentBlockNumberPolygon = await maticProvider.getBlockNumber() - 1
  const currentBlockNumberBsc = await bscProvider.getBlockNumber() - 1

  const oldestBlockNumberPolygon = 22939848
  const oldestBlockNumberBsc = 13763979


  const eventFilterPolygon = Missions.filters.RewardToPay()
  const eventFilterBsc = Rewards.filters.RewardPayed()

  let eventsPolygon = []
  let eventsBsc = []

  for (let i = oldestBlockNumberPolygon; i < currentBlockNumberPolygon - 10000; i += 10000) {
    const eventsLoop = await Missions.queryFilter(eventFilterPolygon, i, i + 10000)
    eventsPolygon = eventsPolygon.concat(eventsLoop)

    const jsonData = JSON.stringify(eventsPolygon);
    fs.writeFile('eventsBsc.json', jsonData.finished)

    console.log(i)
  }

  //for(let i = oldestBlockNumberBsc; i < currentBlockNumberBsc-10000; i+=10000) {
  //const eventsLoop = await Rewards.queryFilter(eventFilterBsc, i, i+10000)
  // eventsBsc = eventsBsc.concat(eventsLoop)
  //console.log(i)
  //}

  console.log('a')
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

JSON.stringify returns a string representation of your JSON. So you cannot do this:

fs.writeFile('eventsBsc.json', jsonData.finished)

Simply write jsonData to the file:

await fs.writeFile('eventsBsc.json', jsonData);

Be aware that this function is async. You need to await it

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