0

Truffle v5.0.5 (core: 5.0.5) Solidity v0.5.0 (solc-js) Node v10.15.1

pragma solidity v0.5.0;


contract ApprovalContracts { 

  address public sender;   
  address public receiver; 
  address public approver = 0xc7780C9521C2C2abED69f0D65BEbF9794C55ae94;  

  function deposit(address _receiver) external payable {  

    require(msg.value >0); 
    sender = msg.sender; 
    receiver = _receiver;
  }

  function viewApprover() external pure returns(address) { 
    return(approver);
  }

  function approve() external { 
    require(msg.sender == approver); 
    receiver.payable(address(this).balance);
  }

}

receiver.payable(address(this).balance); <------ transfer doesn't exist in the new version

I keep getting an error, which is points payable.

ParserError: Expected identifier but got 'payable'
receiver.payable(address(this).balance);

Not sure what im doing wrong.

1

I fiddled with this in Remix to make sure the solution compiles.

The immediate issue is Solidity 0.5.0 introduces a new type, address payable and removes the transfer and send methods from address. To work with payable addresses, cast variables as address payable.

Here: address payable public receiver;

and also here: function deposit(address payable _receiver) external payable {

It looks like receiver.payable was a guess to try to resolve the error. You probably want:

receiver.transfer(address(this).balance);

The compiler wasn't happy with the v in the pragma. When it compiled, it looked like this:

pragma solidity 0.5.0;

contract ApprovalContracts { 

  address public sender;   
  address payable public receiver; 
  address public approver = 0xc7780C9521C2C2abED69f0D65BEbF9794C55ae94;  

  function deposit(address payable _receiver) external payable {  

    require(msg.value >0); 
    sender = msg.sender; 
    receiver = _receiver;
  }

  function viewApprover() external view returns(address) { 
    return approver;
  }

  function approve() external { 
    require(msg.sender == approver); 
    receiver.transfer(address(this).balance);
  }

}

Hope it helps.

  • Problem solved! Thank you! I thought that payable was a replacement for transfer method. – D6ix Mar 6 at 16:15
  • Awesome. If the answer was helpful, please upvote and accept. Thanks. – Rob Hitchens - B9lab Mar 6 at 16:27

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.