smartcontractkit / full-blockchain-solidity-course-py

Ultimate Solidity, Blockchain, and Smart Contract - Beginner to Expert Full Course | Python Edition
MIT License
10.67k stars 2.89k forks source link

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

Open ellyblueeyes opened 1 year ago

ellyblueeyes commented 1 year ago

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

}

0Ksecurity commented 1 year ago

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

cromewar commented 1 year ago

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

itgav commented 1 year ago

@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

ellyblueeyes commented 1 year ago

Thank you!