Solidity

我應該使用哪個編譯器版本?

  • May 9, 2022

’’’ // SPDX 許可證標識符: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;
   } 
}

’''

錯誤 = ParserError: 源文件需要不同的編譯器版本(目前編譯器是 0.8.13+commit.abaa5c0e.Emscripten.clang) - 請注意,夜間建構被認為嚴格低於發布版本 –> @chainlink/contracts/src /v0.6/vendor/SafeMathChainlink.sol:2:1: | 2 | pragma 可靠性 ^0.6.0; | ^^^^^^^^^^^^^^^^^^^^^^^

你犯的錯誤是使用 8.0 版本的 AggregatorV3Interface 和 0.6.0 版本的安全數學,這不是它的工作方式,兩者都使用相同的版本,你很高興,在下面添加程式碼

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

導入“@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol”;

導入“@chainlink/contracts/src/v0.8/vendor/SafeMathChainlink.sol”;

契約基金{

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;

} 

}

您可以嘗試使用語句 - pragma solidity ^0.8.13;

只需複制並粘貼前面的 pragma 語句中的上述行,然後進入編譯器並選擇“0.8.13+commit.abaa5c0e”

引用自:https://ethereum.stackexchange.com/questions/127840