8

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);
13

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)));
| improve this answer | |
  • 1
    thank you for this @K06a – wandos Jun 11 '19 at 6:24
  • 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? – NYC Tech Engineer Feb 20 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 Apr 24 at 16:26
2

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

| improve this answer | |

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.