'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 1:[1]
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.
Solution 2:[2]
Now we can use this line of code to include a range of version of solidity to use. I faced the similar issue and got fixed by doing this:
pragma solidity >=0.4.22 <0.9.0;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Petr Hejda |
Solution 2 | Afzal Zubair |