0

The finaliseRequest transaction is not getting confirmed no matter what I do. I am sure it is failing at the transfer function. I had made the address to address payable also and changed the function too. Any help would be greatly appreciated.

contract InsuranceClaim{
    struct Request {
        address payable insuranceRecipient;
        string personName;
        uint value;
        address payable hospitalRecipient;
        bool complete;

    }
    Request[] public requests;
    address public claimer;

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

    modifier restricted(){
        require(msg.sender==claimer);
        _;
    }

    function createRequest(string memory personName,address payable insuranceRecipient,uint value,address payable hospitalRecipient) public restricted{
        Request memory newRequest = Request({
            insuranceRecipient:insuranceRecipient,
            value:value,
            personName:personName,
            hospitalRecipient:hospitalRecipient,
            complete:false
        });
        requests.push(newRequest);
    }

    function finalizeRequest (uint index) public payable restricted{
        Request storage request = requests[index];
        require(!request.complete);
        request.hospitalRecipient.transfer(request.value);
        request.complete = true;
    }
}
  • Hi and welcome to Ethereum StackExchange! Could you tell us a bit more about what is the error you get when you try to run it? – Lauri Peltonen Dec 10 '18 at 14:50
0

Looks like you don't have any ether on your contract. Add payable fallback function to your contract & transfer some ether there before transferring from it.

or make finalizeRequest request payable depending on your logic.

function finalizeRequest (uint index) public payable restricted {

Also, mark request complete before you transfer ether. It's security issue not related to your question.

  • I am sorry but payable was already there but it still isn't working – Vikranth Dec 10 '18 at 8:14
  • Also it is in remix so it already has ether in it – Vikranth Dec 10 '18 at 8:22
  • @Vikranth do you send enough ether on finalizeRequest call? – petro.sidlovskyy Dec 10 '18 at 8:59
  • @Vikranth welcome, if you accept my answer I would appreciate this :) – petro.sidlovskyy Dec 10 '18 at 23:12

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.