Reputation: 454
I want to send ether to token owner.
ownerOf
returns address, so I set payable address inside of sendEther
function.
However, error says 'Type address is not implicitly convertible to expected type address payable'.
Is there any way to set payable address inside function? Could you give me any advise?
function sendEther(uint256 _tokenId) public payable {
address payable _tokenOwner = ownerOf(_tokenId);
_tokenOwner.transfer(msg.value);
}
ERC721.sol
function ownerOf(uint256 tokenId) public view returns (address) {
address owner = _tokenOwner[tokenId];
return owner;
}
Upvotes: 0
Views: 433
Reputation: 60133
You can't directly cast from address
to address payable
, but you can cast in two steps, through uint160
:
address payable _tokenOwner = address(uint160(ownerOf(_tokenId)));
Upvotes: 1