0

I have two contracts and I'm trying to pass the struct data from one to another, I can do this by creating a mapping and having a uint input associated with that struct but I'd like to get the struct solely based on the address related to it. This compiles but when I execute getC() I get a revert in remix stating "The constructor should be payable if you send value". Any help or suggestions would be appreciated -- Thanks!

First contract:

  struct Campaign {
    address payable campAddress;
    uint goal;
    uint deadline;
    string title;
    uint zipcode;
    Project projAddress;

}

Campaign public campInfo;
Project public projectAddress;

mapping(address => Campaign) public campaignInfo;

   constructor(uint _goal, uint _deadline, string memory _title, uint _zipcode, Project _projAddress) public payable {
   projectAddress = _projAddress;
    campInfo = Campaign(
        msg.sender,
        _goal,
        _deadline,
        _title,
        _zipcode,
        projectAddress
        );  
    campaignInfo[msg.sender] = campInfo;
}
function getCampaign() view public returns(
   address,
    uint ,
    uint  ,
    string memory ,
    uint,
    Project
    ){
    return(
        campInfo.campAddress,
        campInfo.goal,
         campInfo.deadline,
        campInfo.title,
        campInfo.zipcode,
        campInfo.projAddress
        );
}

Second Contract to pass Campaign struct:

Campaigns public campaign;//pass campagin object

constructor(uint amount, address donor, Campaigns campAdress) public payable {
    campaignAddress = address(campAdress);
    donors = Donor(msg.sender,amount,donor, campaignAddress);
    campaign = Campaigns(campaignAddress);
}




   function getC () view  public returns (
    address,
    uint ,
    uint  ,
    string memory ,
    uint,
    Project
       ) {
   return campaign.getCampaign();
}
  • The syntax appear to be correct. Looking at your code one possible problems is that compaign is not the correct contract address. – Ismael Jan 14 at 3:56

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.