0

I have this withdrawal function but an error happens:

TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address". --> sd.sol:138:13: | 138 | msg.sender.transfer(withdrawAmount); | ^^^^^^^^^^^^^^^^^^^

Code:

function withdraw(uint withdrawAmount) public returns (uint remainingBal) {
    // Check enough balance available, otherwise just return balance
    if (withdrawAmount <= balances[msg.sender]) {
        balances[msg.sender] -= withdrawAmount;
        msg.sender.transfer(withdrawAmount);
    }
    return balances[msg.sender];
}

I can send WEI for my contract, so it stores the WEI but I want to be able to withdraw them.

Link do contrato

2
  • 1
    What's the problem exactly? Since 0.8 msg.sender is not payable. To use with transfer or send it has to be converted to payable like this payable(msg.sender).transfer(1 gwei). – Ismael May 9 at 2:48
  • @Ismael worked by doing what you put in, converting it to payable. – Everton Figueiredo May 10 at 10:48
0

The problem was on the line:

msg.sender.transfer(withdrawAmount);

So I had to put msg.sender as payable.

payable(msg.sender).transfer(withdrawAmount);

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.