I am using a CampaignFactory contract to create multiple instances of the Campaign contract and keep track of them. Every campaign is initialized with an array of Struct called rewards. When I try to create a new Campaign with createCampaign in remix, I have the following error:
[vm]from: 0x5B3...eddC4to: CampaignFactory.createCampaign((uint256,uint256,string)[]) 0xd91...39138value: 0 weidata: 0x6d9...00000logs: 0hash: 0xa4d...ad5fd
transact to CampaignFactory.createCampaign errored: VM error: revert.
Here is my code:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.15;
struct Reward {
uint256 contribution;
uint256 maxNumber;
string ImageLink;
}
contract CampaignFactory {
Campaign[] public deployedCampaigns;
function createCampaign(Reward[] memory _rewards)
public
{
Campaign newCampaign = new Campaign(msg.sender);
for (uint256 i = 0; i < _rewards.length; i++) {
newCampaign.createReward(
_rewards[i].contribution,
_rewards[i].maxNumber,
_rewards[i].ImageLink
);
}
deployedCampaigns.push(newCampaign);
}
function getDeployedCampaigns()
public
view
returns (Campaign[] memory)
{
return deployedCampaigns;
}
}
contract Campaign {
Reward[] public rewards;
address public manager;
modifier restricted() {
require(msg.sender == manager);
_;
}
constructor(address creator) {
manager = creator;
}
function createReward(
uint256 _contribution,
uint256 _maxNumber,
string memory _imageLink
) public restricted {
Reward memory newReward = Reward({
contribution: _contribution,
maxNumber: _maxNumber,
ImageLink: _imageLink
});
rewards.push(newReward);
}
}