I have a contract that allows user to create a campaign and people can bid. I am reading the data to frontend using etherjs. It take time to load campaigns and as more campaigns are created it becomes slower.
This is my createCampaign code
struct Campaign {
uint256 campaignID;
string brand;
uint256 budget;
mapping(uint => Bidder[]) bidders;
}
struct Bidder {
bool bided;
uint256 bid;
string name;
address bidderAddress;
}
Campaign[] public campaigns;
uint totalCampaign = 0; //same with one above
//-------Creating a Campaign-------//
function createCampaign(
string memory _brand,
uint256 _budget
) public {
Campaign storage _initialCampaign = campaigns.push();
_initialCampaign.campaignID = totalCampaigns += 1;
_initialCampaign.brand = _brand;
_initialCampaign.budget = _budget;
totalCampaign++;
}
How can I read data faster to frontend?
Instead of returning them all return them one by one and fetch them in the front end when they reach or you can save the president data from you mango or sql database and then retrieve other data when needed from blockchain