Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript — 32-Hour Course

By Scofield | LearnHub_Africa | 5 Sep 2022


 

I am sharing my learning path with 

Patrick Collins

, “Learn Blockchain, Solidity, and Full Stack Web3 Development with JavaScript — 32-Hour Course” so you can follow.

 

 

 

Find my codes here

 

 

 

In week 4, I learned how to use the constant and immutable keywords to save gas on my transactions, I saw how constant can be used when the syntax is on a single line, for example, uint public MIN_AMOUNT = 50;

 

We can insert the constant here to save the variable inside the byte data.

uint public constant MIN_AMOUNT = 50;

in a situation where our variable is used in multiple lines like the constructor, we can use the immutable keyword on the variable function.

address public immutable i_owner

constructor{ i_owner = msg.sender; }

Using the require statement cost a lot of gas, so to save gas we use the error, and create the error function above the contract.

error Not_Owner;

on the modifier

modifier onlyowner{

if (msg.sender == i_owner) {revert notOwner();}

_;

}

I also learned how to use the fallback and receive function, this works in a case where someone tries to integrate with my smart contract by not calling the fundAcount we created.

Once a funder sends ETH to our smart contract let’s say directly from metamask, it is quickly updated and sent to fundaccount functions through the receive function, like so

receive() external payable { fundacount();

}

if the user sends something other than a transaction, our fallback function, which is like a fail-safe for our contract, pushes it back to receive if it is outlined in our fundaccount function, and it throws an error.

I also came across the constructor function but I have used it before, the constructor is called before any other thing in the contract this allows for malicious actors not to call a payout function

I set the constructor as the owner of the contract thereby making sure when another address calls the payout functions our smart contract blocks it.

See you all in week 5.

How do you rate this article?

16


Scofield
Scofield

Smart Contract/Solidity || Python || Reactjs || Every other thing is just hobbies


LearnHub_Africa
LearnHub_Africa

The emergence of tech has created the need for constant updates on new technology and their functions and this is what we are about, from CSS. Cybersecurity, Web3, Data Science etc. We have you covered.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.