PatrickAlphaC / hardhat-fund-me-fcc

82 stars 184 forks source link

A red underline under the bracket of FundMe__NotOwner() #36

Closed asmar10 closed 2 years ago

asmar10 commented 2 years ago
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

error FundMe__NotOwner() [ ### THIS IS WHERE A RED UNDERLINE APPEARS IN MY SOLIDITY FILE];


contract FundMe {
    using PriceConverter for uint256;

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

    // Could we make this constant?  /* hint: no! We should make it immutable! */
    address public /* immutable */ i_owner;
    uint256 public constant MINIMUM_USD = 50 * 10 ** 18;

    AggregatorV3Interface public priceFeed;

    constructor(address _priceFeedAddress) {
        priceFeed = AggregatorV3Interface(_priceFeedAddress);
        i_owner = msg.sender;
    }

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

    modifier onlyOwner {
        if (msg.sender != i_owner){ revert FundMe__NotOwner();}
        _;
    }

    function withdraw() payable  public {
        for (uint256 funderIndex=0; funderIndex < funders.length; funderIndex++){
            address funder = funders[funderIndex];
            addressToAmountFunded[funder] = 0;
        }
        funders = new address[](0);   
        (bool callSuccess, ) = payable(msg.sender).call{value: address(this).balance}("");
        require(callSuccess, "Call failed");
    }

    fallback() external payable {
        fund();
    }

    receive() external payable {
        fund();
    }

}```

 is there anything wrong with the OnlyOwner() ;
RoboCrypter commented 2 years ago

Hello friend: please replace this line of code : if (msg.sender != i_owner){ revert FundMe__NotOwner();} to if(msg.sender != i_owner) revert FundMe__NotOwner();

Hopefully .. It will work

PatrickAlphaC commented 2 years ago

Thanks @ABossOfMyself !