Web3 Solidity + JavaScript 32 hour course recap #13
Amy's Vue on this
Posted on June 9, 2022
timestamps: 4:20:00 - 4:33:33
This is a recap of me making my way through the 32 hour course by Patrick Collins posted on FreeCodeCamp.
I started off by reviewing mapping vs arrays, because we're going through this material rather quickly and needed the refreshers. Mappings are hashes (key/value pair), and arrays are arrays.
Then we reviewed interfaces, which define which functions are available in a contract, and can be imported and used as the ABI since we need the ABI and the contract address to interact with 3rd part contracts.
Here is the Global Variable Cheatsheet from the Solidity documentation. It lists all of the variables that are available to us "for free" globally.
Solidity by Example was mentioned as a good resource yesterday, but we specifically went to the library lesson.
It turns out that Solidity libraries are like contracts except they're defined as library
instead of contract
and the functions should be internal
instead of public
. They also cannot have any state variables, and they cannot handle Ethereum.
It was also a cool trick to import the library, and then define a type as
that, so that we could then just chain it on uint256. In a library function, the thing that's changed on that is that result is the first parameter inside that goes to that library function.
import "./PriceConverter.sol";
using PriceConverter for uint256;
msg.value.getConversionRate()
the PriceConverter.sol has the getConversionRate
defined as:
function getConversionRate(uint256 ethAmount) internal view returns (uint256){
As an aside: if you have a section collapsed in Remix, and you try to search for a term; it will not find it.
I did not learn for a full hour tonight, but I did learn about libraries, so I've got that going for me - which is nice.
Posted on June 9, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.