fund_me
fund_me copied to clipboard
Fund
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);
}
}
`
Are you sure the adresses that you have (rinkebin) is same as your metamask test network? (Both needs to be rinkebin or kovan etc.)
Did you ever figure this out? Stuck at the same issue. I suspect it could be an error with importing the SafeMath library since the rest of the code matches and the SafeMath library could have been updated since this course was released
Man I forget how I got through this... I remember for awhile I played with decimals... I think I changed
uint256 minimumUSD = 50 * 10 ** 18;
to
uint256 minimumUSD = 0.5 * 10 ** 18;
But then a day or two later I was back at it and further into the course I had another issue and I changed it back to
uint256 minimumUSD = 50 * 10 ** 18;
So my only guess is proceed and the fix is another 10 - 30 min into the course 🤷♂️
P.S. sorry for the delayed response
@Dcamy @amandacat222
.
Are you guys doing this with the Injected Web3 (Injected Provider - metamask) environment?
.
I am doing the course right now and it's working for me (using the metamask
plugin for Firefox).
.
I just had to change the ETH/USD feed address to 0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e
here and here, because I am using the Goerli network (got the correct address from here).
.
Also, like it's written in this comment, I changed those lines accordingly (wrapped msg.sender
in the payable()
function) since I'm using solidity v0.8.0
.
.
I hope that helps. Good luck!
.
.
EDIT: Also, what I did was change that minimumUSD
value to only 1 USD (1 * 10 ** 18) and I used this converter to spend a little over a dollar (at the time of this writing 700000000000000 Wei
or 700000 Gwei
or 0.0007 Ether
) to fund my contract, and it worked like a charm!