1

enter image description here

below is my code :

function withdraw() external isOwner() {
        address payable owner = address(uint160(getOwner()));
        owner.transfer(address(this).balance);
    }

what is wrong in the address conversion error, can anyone help?

1 Answer 1

0

As of solidity 0.6, you can cast address to address payable via

address addr = 0x****;
address payable wallet = payable(addr);

..so, in this case, try the following edit:

function withdraw() external isOwner() {
        address payable owner = payable(getOwner());
        owner.transfer(address(this).balance);
    }

NotaBene

I’m unsure as to wether or not this will successfully compile since you haven’t shared your code for the function call isOwner'() - it seems odd to call a function in declaring a function. Each to his own, of course, I’m just unsure if this will successfully compile

3
  • The way i understand it is that isOwner is just a modifier (the parenthesis are optionnal when the modifier don't take in any arguments, but leaving them in is still correct syntax). I'm more wierded out by the wierd type conversion done when calling getOwner(). Why is it being converted to an uint160 first? Was that a blind attempt to fix the error, or does getOwner returns an uint256 or something like that? If that's the case they'd have to do payable(address(uint160(getOwner());
    – Foxxxey
    Jan 31, 2023 at 2:51
  • I have taken the logic based on in the below document- docs.soliditylang.org/en/latest/types.html#address
    – Baby
    Jan 31, 2023 at 3:13
  • That’s an interesting thought. I’d suppose of you still got a Implicit Conversion error after the above edit (since we don’t have the code here for getOwner()) , that would be the next bet
    – immaxkent
    Jan 31, 2023 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.