1

I am confused why the following code is not working. Any help would be greatly appreciated.

pragma solidity >=0.4.22 <0.6.0

contract InsuranceClaimFactory{
    address public claimer;
    address[] public deployedInsuranceClaim;
    function createInsuranceClaim () public {
        address newInsuranceClaim = new InsuranceClaim(msg.sender);
        deployedInsuranceClaim.push(newInsuranceClaim);
    }

    function getDeployedInsuranceClaims () public view returns (address[] memory){
        return deployedInsuranceClaim;
    }
}

The constructor for InsuranceClaim is

constructor (address creator) public {
claimer=creator;
}

The error is

TypeError: Type contract InsuranceClaim is not implicitly convertible to expected type address

  • What behaviour you are expecting with new InsuranceClaim(msg.sender)? – Aniket Dec 4 '18 at 11:01
  • It seems like may be 0.4.99 or greater versions change the syntax of a creating object but in a lower version like 0.4.24 this code runs without error. – Mahesh Rajput Dec 4 '18 at 11:23
2

ERROR: Type contract InsuranceClaim is not implicitly convertible to expected type address means you can not store InsuranceClaim type of object in address variable. AS per solidity version 0.5.0 Documentation you can define and use InsuranceClaim like this:

pragma solidity>0.4.99<0.6.0;

contract InsuranceClaimFactory{
    address public claimer;

    InsuranceClaim[] public deployedInsuranceClaim;
    function createInsuranceClaim () public {
        InsuranceClaim newInsuranceClaim = new InsuranceClaim(msg.sender);
        deployedInsuranceClaim.push(newInsuranceClaim);
    }

    function getDeployedInsuranceClaims () public view returns (InsuranceClaim[] memory){
        return deployedInsuranceClaim;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.