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

119
Views
I cannot get a list of requests from solidity to javascript

as far as I know I cannot get an array of structs from solidity to javascript, so make individual request for each request from javacript:

 const address = context.params.id;
  const campaign = Campaign(address);
  const requestCount = await campaign.methods.getRequestsCount().call();
  const donatorsCount = await campaign.methods.donatorsCount().call();
  // this returns: requests.count 4
  console.log("requests.count", requestCount);
  const requests = await Promise.all(
    Array(requestCount)
      .fill()  // I tried fill(0)
      .map((element, index) => {
        return campaign.methods.requests(index).call();
      })
  );
  console.log("requests", requests);

I have 4 requests but I always get only the first request

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The requestCount contains string value 4.

And because it's not a Number type specifying the array length, the Array() constructor takes it as one element (value "4") of the newly created array.

Solution: pass the value as type Number to create a 4-item array.

Array(parseInt(requestCount))

Instead of looping through each index, you can also create a Solidity function that returns the whole array

function getRequests() external view returns (Request[] memory) {
    return requests;
}

and call it from JS

const requests = await campaign.methods.getRequests().call();
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!