0

I get the following error

type address is not implicitly convertible to expected type address payable on the withdraw function.

pragma solidity ^0.8.1;

contract sendMoneyExamples{
    uint public getRecivedMoney;
    function reciveMoney()public payable{
        getRecivedMoney=getRecivedMoney+msg.value;
    }
    function getBalance()view public returns(uint){
        return address(this).balance;
    }
    function withdraw()public {
        address payable to = msg.sender;
        to.transfer(this.getBalance());
    }
    function withdrawato(address payable _to)public{
        _to.transfer(getBalance());
    }
}
0

The type of the 'to' variable is address payable whereas the type of msg.sender is address. You can't implicitly convert an address to address payable as the error states. Remove the payable keyword from the to variable and it will be fine.

1

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.