0

Just upgraded truffle to version 5 and having a problem with this new address payable type.

contract Test {
  ERC721Full public tokenAddress;

  constructor(address _address) public {
    tokenAddress = ERC721Full (_address);
  }

  function sendToOwner(...) public payable {
    address payable owner = tokenAddress.ownerOf(_tokenId);
    owner.transfer(msg.value);
  }
}

So I'm trying to send ether to owner account, but I'm getting

TypeError: Type address is not implicitly convertible to expected type address payable.

How to fix this?

3
  • Ask yourself what is the return-value type of function ownerOf. Aug 9 '19 at 7:46
  • address does that mean i need casting?
    – bbusdriver
    Aug 9 '19 at 7:56
  • Yes it does..... Aug 9 '19 at 11:49
1

tokenAddress.ownerOf() probably returns an address, not address payable. See this thread for a way to do that: Convert contract to payable address

0

this question might be old, and the answer got already approved.

but I stumbled upon this question looking for an answer and didn't find what I was looking for, so for the peeps that come here in the future (after 0.8.0),

the answer you are looking for is:

change this

owner.transfer(msg.value);

To this :

payable(owner).transfer(msg.value);

so basically the default addresses cannot be changed to payable addresses, but they can be wrapped by payable(address) to have that functionality in times of need :D

hope this answer was helpful

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.