25

Got address from 3rd-party library:

address wallet = rlp[5].toAddress();

And wanna transfer some funds to it:

wallet.transfer(amount);

Got error:

TypeError: Member "transfer" not found or not visible after argument-dependent lookup in address.
        wallet.transfer(amount);
        ^-------------^

And casts not works:

((address payable)(wallet)).transfer(amount);

2 Answers 2

39

Solidity 0.6.x:

Here is how to cast address to address payable:

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

And contract cast to address payable:

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

Solidity 0.5.x:

Here is how to cast address to address payable:

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

And contract cast to address payable:

MyContract addr = MyContract(0x****);
address payable wallet = address(uint160(address(addr)));
3
  • 1
    This worked, thank you. But I don't know why or understand how it works. Seems really janky, is there no other way to do it? Commented Feb 20, 2020 at 23:22
  • 1
    @NYCTechEngineer, in Solidity 0.6.0, you can now just do payable(addr) to convert an address to an address payable. See solidity.readthedocs.io/en/v0.6.0/types.html#address.
    – erwaman
    Commented Apr 24, 2020 at 16:26
  • All I get is ParserError: Hexadecimal digit missing or invalid. Sol 0.5.16.
    – Joe Molnar
    Commented Sep 6, 2021 at 23:51
4

In Solidity ^0.6.0, you can just use payable(addr). Ref: https://solidity.readthedocs.io/en/v0.6.0/types.html#address

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.