Skip to content

Fund #13

@Dcamy

Description

@Dcamy

I'm having an issue with the Fund function, I've gone through all the issues here but not finding a solution that works. I get the same error for any fund amount, from any wallet, in gwie, and wie. The error I get is the one expected when funding with the wrong amount.

I'm pretty new to all of this so guessing the issue is user error but I am a bit lost here. If I comment out

uint256 minimumUSD = 50 * 10 ** 18; and require(getConversionRate(msg.value) >= minimumUSD, "You need to spend more ETH!");

Everything works.

Is this user error or.?.My code below for reference

`// SPDX-License-Identifier: MIT

pragma solidity >=0.6.6 <0.9.0;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/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 {
    //The next two line fail every transaction, need to sort out what is going on here
    uint256 minimumUSD = 50 * 10 ** 18;
    require(getConversionRate(msg.value) >= minimumUSD, "You need to spend more ETH!");
    // found on GitHub... didn't work
    // require(getConversionRate(msg.value / 10 ** 9) >= 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(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);
    return priceFeed.version();
}

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

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

modifier onlyOwner {
    require(msg.sender == owner, "Why you try to take our money? :(");
    _;
}

function withdraw() payable onlyOwner public {
    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);
}

}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions