Search code examples
blockchainsoliditychainlink

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


I was eventually trying to run this code in remix IDE, where I was running this using 0.6.6 version of Solidity and ran into this error. I've tried using some other versions like 0.8 and 0.6 as well.

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

Solution

  • Your code requires Solidity 0.8.7, but the imported SafeMathChainlink.sol requires Solidity 0.6.*.

    An easy solution is to change your code to require v0.6 as well and compile with this version.

    pragma solidity ^0.6.0;
    

    Or you can remove the import and using ... for of the SafeMath library, as it's not needed on 0.8 anymore. All validations performed in the library are now performed on the language level since version 0.8.0.