如何将以太币发送给 erc721 令牌所有者?

How to send ether to erc721 token owner?

我想发送以太币给代币所有者。

ownerOf returns 地址,所以我在 sendEther 函数中设置了支付地址。

但是,错误显示 'Type address is not implicitly convertible to expected type address payable'。

有什么方法可以在函数内部设置收款地址吗? 你能给我什么建议吗?

  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;
    }

你不能直接从address投射到address payable,但你可以分两步投射,通过uint160:

address payable _tokenOwner = address(uint160(ownerOf(_tokenId)));