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

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

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 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!