Skip to content

Lesson 4 FundMe contract #6798

Closed Answered by 0xdothis
0xdothis asked this question in Q&A
Discussion options

You must be logged in to vote

Firstly i will explain the problems, then explain my solutions.

Problem

uint256 public MINIMUM_USD = 50 * 1e18;

or

uint256 public MINIMUM_USD = 50 * 10 ** 18;

The above code will convert 50 to 50eth but in wei.
if we now call the fund() function we need to send more than 50eth in wei for the transaction to pass

 require(msg.value.getConversionRate() >= MINIMUM_USD), "Didn't send enough ETH");

Solution

I created a function in the PriceConverter.sol library that allows us to convert usd to wei equivalent of eth

function convertUsdToEth(uint256 _ethAmountInUsd) internal view returns (uint256) {
        uint256 ethPrice = getPrice() / 1e18;
        uint256 ethAmountInWei = (_ethAmountInUsd * 1…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by 0xdothis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant