How can I pass struct from one contract to another?

by BluLotus   Last Updated January 10, 2019 23:28 PM

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();
}


Related Questions


Updated January 31, 2019 07:28 AM

Updated January 02, 2019 03:28 AM

Updated January 26, 2019 18:28 PM

Updated July 20, 2018 04:28 AM