ParserError: Source file requires different compiler version (current compiler is 0.8.7+commit.e28d00a7.Emscripten.clang)

ParserError: Source file requires different compiler version (current compiler is 0.8.7+commit.e28d00a7.Emscripten.clang)

我最终试图 运行 重新混合 IDE 这段代码,我是 运行 使用 0.6.6 版本的 Solidity 和 运行错误。我也尝试过使用其他一些版本,例如 0.8 和 0.6。

// SPDX-License-Identifier: MIT

pragma solidity =0.8.7;

import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";

contract myContract{
    using SafeMathChainlink for uint256;
    mapping(address => uint256) public payTo;

    function Payment() public payable {
        uint256 minimumUSD = 50 * 10 ** 18;
        require(getConversionRate(msg.value) >= minimumUSD, "Doesn't satisfy the minimum condition");
        payTo[msg.sender] += msg.value;
    }
}

您的代码需要 Solidity 0.8.7,但导入的 SafeMathChainlink.sol 需要 Solidity 0.6.*.

一个简单的解决方案是将您的代码更改为也需要 v0.6 并使用此版本进行编译。

pragma solidity ^0.6.0;

或者您可以删除 SafeMath 库的 importusing ... for,因为 0.8 不再需要它。自版本 0.8.0 以来,在库中执行的所有验证现在都在语言级别执行。

现在我们可以使用这行代码来包含一系列要使用的solidity版本。我遇到了类似的问题并通过这样做得到解决:

pragma solidity >=0.4.22 <0.9.0;