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

200
Views
¿Cómo escribir datos de matriz en json?

Cómo escribir los datos que pasa el ciclo a la matriz "eventsPolygon", a json. Esta matriz devuelve 4 argumentos. Con este método, aparece el error "Error de tipo [ERR_INVALID_CALLBACK]: la devolución de llamada debe ser una función. Recibido indefinido"

 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 answers
Answer question

0

JSON.stringify devuelve una representación de cadena de su JSON. Entonces no puedes hacer esto:

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

Simplemente escriba jsonData en el archivo:

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

Tenga en cuenta que esta función es asíncrona. Tienes que await

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!