Tokens

TypeError:從地址到地址的隱式轉換無效請求

  • October 14, 2021

大家怎麼了!

我正在努力為我的 ERC-721 智能合約增加版稅。我的目標是每當有人鑄造新代幣或轉讓代幣時,將版稅返還給藝術家。

但是,現在我在嘗試遷移契約時遇到錯誤。

TypeError: Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested

          setRoyalties(_tokenIdTracker.current(),devAddress,2000);
                                                 ^^^^^^^^^

這是我的契約


//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "./@rarible/royalties/contracts/impl/RoyaltiesV2Impl.sol";
import "./@rarible/royalties/contracts/LibPart.sol";
import "./@rarible/royalties/contracts/LibRoyaltiesV2.sol";

contract EpicTest is ERC721, Ownable, RoyaltiesV2Impl {
   
   using SafeMath for uint256;
   using Counters for Counters.Counter;
   Counters.Counter private _tokenIdTracker;

   uint256 public constant MAX_ELEMENTS = 1000;
   bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a;
   uint256 private startSales = 1634124766;
   
   address public constant artistAddress = 0xcBC0x0x0x0x0x0x0x0x0x0x0x0;

   constructor() ERC721("EpicTest", "ET") {}
   
   function mint(address _to) public onlyOwner {
       super._mint(_to, _tokenIdTracker.current());
       setRoyalties(_tokenIdTracker.current(),artistAddress,2000);
       _tokenIdTracker.increment();
   }


   function setRoyalties(uint _tokenId, address payable _royaltiesReceipientAddress, uint96 _percentageBasisPoints) public onlyOwner {
       LibPart.Part[] memory _royalties = new LibPart.Part[](1);
       _royalties[0].value = _percentageBasisPoints;
       _royalties[0].account = _royaltiesReceipientAddress;
       _saveRoyalties(_tokenId, _royalties);
   }

   function royaltyInfo(uint256 _tokenId, uint256 _salePrice) external view returns (address receiver, uint256 royaltyAmount) {
       LibPart.Part[] memory _royalties = royalties[_tokenId];
       if(_royalties.length > 0) {
           return (_royalties[0].account, (_salePrice * _royalties[0].value)/10000);
       }
       return (address(0), 0);
   }
   

}

我使用 EpicEagles 合約作為參考智能合約程式碼,他們似乎在做類似的事情,我可能錯過了一步。任何幫助將不勝感激,在此先感謝您。

我試過的:

  • 應付地址常量 ArtistAddress = 0xcBC0x0x0x0x0x0x0x0;

您的呼叫正在發送devAddresssetRoyalties期望在其位置的方法address payable _royaltiesReceipientAddress。由於它需要函式上的paybale地址,因此您必須在它進入方法之前對其進行轉換,您可以通過payable在呼叫函式時將其轉換為:

setRoyalties(_tokenIdTracker.current(),payable(devAddress),2000);

引用自:https://ethereum.stackexchange.com/questions/111537