DEV Community

Amy's Vue on this
Amy's Vue on this

Posted on

2 1

Web3 Solidity + JavaScript 32 hour course recap #12

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!

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay