1
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

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

contract fundme {
    mapping(address => uint256) public addtofunded;
    function fund() public payable {
        addtofunded[msg.sender] += msg.value;
    }
    function get_version() public view returns (uint256){
        AggregatorV3Interface priceFeed = 
AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
        return priceFeed.version();
    }
    function get_price() public view returns(uint256){
        AggregatorV3Interface priceFeed = 
AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
        (,int256 answer,,,) = priceFeed.latestRoundData();
        return uint256(answer * 10000000000);
    }
    function convert(uint256 ethamt) public view returns(uint256){
        uint256 ethprice = get_price();
        uint256 ethamttousd = (ethprice * ethamt) / 1000000000000000000; 
        return ethamttousd;
    } 
}

The error:

ParserError: Source file requires different compiler version (current compiler is 0.8.13+commit.abaa5c0e.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version
--> @chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol:2:1:
  |
2 | pragma solidity ^0.6.0;
  | ^^^^^^^^^^^^^^^^^^^^^^^

3 Answers 3

1

The mistake you did was using 8.0 version for AggregatorV3Interface and 0.6.0 version for SafeMath. That's not how it will work, use same version for both and you are good to go. Added code below.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

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

contract fundme {

    mapping(address => uint256) public addtofunded;

    function fund() public payable {
        addtofunded[msg.sender] += msg.value;
    }
    function get_version() public view returns (uint256){
        AggregatorV3Interface priceFeed = 
          AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
        return priceFeed.version()
    }

    function get_price() public view returns(uint256){
        AggregatorV3Interface priceFeed = 
      AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
        (,int256 answer,,,) = priceFeed.latestRoundData();

        return uint256(answer * 10000000000);
    }

    function convert(uint256 ethamt) public view returns(uint256){

        uint256 ethprice = get_price();

        uint256 ethamttousd = (ethprice * ethamt) / 1000000000000000000; 
        return ethamttousd;

    } 

}
1
  • thanks sunny isssue has been solve i used the v0.6 of both library
    – Hitesh
    May 9, 2022 at 11:45
0

You can try with the statement - pragma solidity ^0.8.13;

Just copy and paste the above line in the previous pragma statement and then go into Compiler and Select "0.8.13+commit.abaa5c0e"

1
  • after adding that error = 'ParserError: Source file requires different compiler version (current compiler is 0.8.13+commit.abaa5c0e.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version --> @chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol:2:1: | 2 | pragma solidity ^0.6.0; | ^^^^^^^^^^^^^^^^^^^^^^^'
    – Hitesh
    May 9, 2022 at 4:18
0

use latest version. e.g.- pragma solidity 0.8.13; or pragma solidity >0.8.0 <0.9.0;

check latest version from official website: https://soliditylang.org/

NOTE: If your solidity have some deprecated functions then use older versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.