full-blockchain-solidity-course-py icon indicating copy to clipboard operation
full-blockchain-solidity-course-py copied to clipboard

FundMe.sol Error: not found @chainlink/contracts/src/v0.8/vendor/SafeMathChainlink.sol

Open ellyblueeyes opened this issue 2 years ago • 4 comments

Hello, I am trying to run this code in the terminal but I get this Error: not found @chainlink/contracts/src/v0.8/vendor/SafeMathChainlink.sol. I updated the version for solidity. I understand that SafeMath is no longer necessary for solidity 0.8 version, but I don't know how to modify the code so that it can work. Thank you for help.

// SPDX-License-Identifier: MIT

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 {

using SafeMathChainlink for uint256;


mapping(address => uint256) public addressToAmountFunded;
address[] public funders;
address public owner;

  constructor() public {
    owner = msg.sender;
}

function fund() public payable {
    uint256 minimumUSD = 50 * 10**18;
    require(
        getConversionRate(msg.value) >= minimumUSD,
        "You need to spend more ETH!"
    );
 
    addressToAmountFunded[msg.sender] += msg.value;
    funders.push(msg.sender);
}

  function getVersion() public view returns (uint256) {
    AggregatorV3Interface priceFeed = AggregatorV3Interface(
        0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e
    );
    return priceFeed.version();
}

function getPrice() public view returns (uint256) {
    AggregatorV3Interface priceFeed = AggregatorV3Interface(
        0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e
    );
    (, int256 answer, , , ) = priceFeed.latestRoundData();
         return uint256(answer * 10000000000);
}

function getConversionRate(uint256 ethAmount)
    public
    view
    returns (uint256)
{
    uint256 ethPrice = getPrice();
    uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1000000000000000000;
         return ethAmountInUsd;
}

 modifier onlyOwner() {
          require(msg.sender == owner);

    _;
}

function withdraw() public payable onlyOwner {
    msg.sender.transfer(address(this).balance);

         for (
        uint256 funderIndex = 0;
        funderIndex < funders.length;
        funderIndex++
    ) {
        address funder = funders[funderIndex];
        addressToAmountFunded[funder] = 0;
    }
         funders = new address[](0);
}

}

ellyblueeyes avatar Sep 29 '22 12:09 ellyblueeyes

Hi .. check if you install chainlink to your code .

0Ksecurity avatar Oct 06 '22 02:10 0Ksecurity

Hello @ellyblueeyes As you want to use the solidity version 0.8, you don't need the safeMath import. Try deleting it.

cromewar avatar Oct 08 '22 21:10 cromewar

@cromewar is correct. Additionally, the import is not found because it doesn't not exist at the given path. If you go to that file path on GitHub 'SafeMathChainlink.sol' does not exist. It stops after 'v0.7' due to lack of need with Solidity v0.8.0

itgav avatar Nov 27 '22 15:11 itgav

Thank you!

ellyblueeyes avatar Nov 27 '22 18:11 ellyblueeyes