In my next js app, I have the following function:
export async function getServerSideProps(ctx) {
const campaign = campaignInstance(ctx.params.address);
const requestCount = await campaign.methods.getRequestsCount().call();
console.log(requestCount);
console.log(Array(requestCount).fill());
// This is my current objective...
// Since I can't retrieve a complete array of structs from
// a Solidity smart contract, I am fetching each element individually.
const requests = await Promise.all(
Array(requestCount).fill().map((element, index) => {
return campaign.methods.requests(index).call();
})
);
return {
props: {
requests: JSON.stringify(requests),
address: ctx.params.address
}
};
}
When I check my console, I see the following output:
4
[ undefined ]
At first glance, I expected to see an array with 4 undefined elements. The value of requestCount
is clearly 4.