【问题标题】:Type address is not implicitly convertible to expected type address payable. owner = msg.sender类型地址不能隐式转换为预期的应付类型地址。所有者 = msg.sender
【发布时间】:2022-07-19 14:57:14
【问题描述】:

编译时出现此错误。我知道它与 v8 有关,我需要支付它们,我做到了,但仍然无法正常工作。好心人能帮上忙吗?

contract FundMe {
    
    mapping(address =>uint256) public addressToAmountFunded;
    
    address payable[] public funders;
    
    address payable public owner;
    
    constructor() public {
        owner = msg.sender; //LINE WITH ERROR
    }
    
    function fund() public payable {
        uint256 minimumUSD = 50 * 10 ** 18; 
        
        require(getConversionRate(msg.value) >= minimumUSD, "you need to spend more ETH my friend");
        
        addressToAmountFunded[msg.sender] += msg.value;
        
        funders.push(msg.sender); //ERROR AS WELL
        
    }

【问题讨论】:

    标签: solidity


    【解决方案1】:

    尝试像下面这样包装地址:

    payable(msg.sender)
    

    【讨论】:

    • 是的。就是这样......谢谢!
    【解决方案2】:

    我在编译时遇到错误,我完全不知道可能是什么问题,我非常需要帮助。

    function _addTokensToOwnerEnumeration(address to, uint256 tokenId) private { // EXERCISE - CHALLENGE - DO THESE THREE THINGS: // 1. add address and tokenId to the _ownedTokens // 2. ownerTokensIndex tokenId set to address of // ownedTokens position // 3. we want to execute the function with minting // 4. Bonus is to compile and test _ownedTokensIndex[tokenId] = _ownedTokens[to].length; _ownedTokens[to].push(tokenId); }

    这是错误

    ,TypeError: 类型地址不能隐式转换为预期类型 uint256。 --> 项目:/src/contracts/Interfaces/Libraries/ERC721Enumerable.sol:83:51: | 83 | _ownedTokensIndex[tokenId] = _ownedTokens[to].length; | ^^

    ,TypeError: 类型地址不能隐式转换为预期类型 uint256。 --> 项目:/src/contracts/Interfaces/Libraries/ERC721Enumerable.sol:84:22: | 84 | _ownedTokens[to].push(tokenId); |

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 2017-09-05
      • 2022-08-19
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多