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

185
Views
TypeError: Cannot read properties of undefined (reading '0'). Terminal hit this error after deployment of script

I get such a problem in my code. I fight and fight, I still haven't found an error :(

Terminal after call this script hit " TypeError: Cannot read properties of undefined (reading '0')"


  const nft = "cardienft.json";

  
  let rares = JSON.parse(fs.readFileSync(nft));
  let nonce = 73;
  for(let i = 0; i < 2000; i += 25) {
      let moonies = [];
      for(let j = 0; j < 25; j++) {
        moonies.push({ uri: rares.doggies[i+j].uri, moonieType: 6 });
      }
      console.log(await Gateway.forgeRares(moonies, { gasLimit: 10000000, gasPrice: 2000000000, nonce: nonce }));
      nonce++;
      console.log(i + ' to ' + (i+25) + ' forged');
  } ```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

when your code arrives at this line :

moonies.push({ uri: rares.doggies[i+j].uri, moonieType: 6 });

rares is an empty object , so rares.doggies is undefined

i and j are 0 and i+j = 0 it want to read 0 key from undefined(rares.doggies).

you can log rares before starting for loop to get sure and then handle its value

or you can add a ? between rares.doggies and [i+j] like this:

moonies.push({ uri: rares.doggies?.[i+j].uri, moonieType: 6 });

as a trick

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!