timestamps: 4:11:11 - 4:22:02
This is a recap of me making my way through the 32 hour course by Patrick Collins posted on FreeCodeCamp.
There was a lot of user error this time -.-;
However, we made a lot of progress in our "FundMe" SmartContract.
Basically, to have $50 in ethereum, we have to use 50 and set it to 10e18:
uint256 public minimumUsd = 50 * 1e18;
This is because WEI is 18 decimal places.
Then we completed the getBlockchainPrice
function. Which connects to the Aggregator with the address provided in Chainlink.
AggregatorV3Interface priceFeed = AggregatorV3Interface(ethToUsdAddress);
This function also taught us about Solidity destructing, which is possible as long as you leave in the commas to account for the values that you don't need to use.
(, int256 price, , ,) = priceFeed.latestRoundData();
One of the variables lets you know about the decimal place, but in order for it to display the correct currency amount is is only e10.
return uint256(price * 1e10);
Next, the getConversionRate
method takes in the global value that was sent with the transaction, and converts it to the correct amount of Ethereum, by getting the current price of Ethereum:
uint256 ethPrice = getBlockchainPrice();
and then
uint256 ethAmountInUsd = (ethPrice * ethAmount) / 1e18;
With solidity, you have to multiply first and then divide so basically 101/100 to get 1%. Something Something floating point math, and we want to be accurate when it comes to money.
I didn't get terribly far today, but we made good progress in the app. If I had to guess, we'll be getting to the meat of the fund
method soon!
Top comments (0)