Solidity – Fix for ‘Type Address is Not Implicitly Convertible to Expected Type Address Payable’

solidity

I'm taking the course from lynda.com "Ethereum: Building Blockchain Decentralized Apps (DApps)" but there's an issue with the contract we're given, and it won't compile:

pragma solidity ^0.5.0;

contract ApprovalContract {
    address payable public sender;
    address payable public receiver;
    address public constant approver = 0x3999BA5D247c800E5Ef3d4de66618741E3675379 ;

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.transfer(address(this).balance);
        
    }
}

Here the picture from the result of trying to compile the solidity contract:

enter image description here

Best Answer

This casting worked for me:

casted "address" to "address payable" with "payable(msg.sender)".

Related Topic