Day-03: Blockchain Basics - Solidity #100DaysOfCode #MyLearnings

Day-03: Blockchain Basics - Solidity #100DaysOfCode #MyLearnings

·

4 min read

Table of contents

Welcome back to yet another daily blog folks!

Intro

This is the day I finally get to code in Solidity, very little but better than just going through the theory lectures. Before I get into code let's discuss something called the Tutorial Hell. So, I was going through Harkirat Singh's video the other day, in which he was talking about not getting into a tutorial hell for self-taught software developers (click here for the video).

The question that came to my mind was am I getting or been in the tutorial hell? And, yet I was... When I thought of exploring other techs like Ts-Nodejs, Computer Vision, or Nestjs, I went through multiple tutorials, though I used the documentation as a reference, but still that was the case. And, now I am following up on a 32**-hour-**long blockchain course, is it another hell? Well, I would say NO. Cause it's about my learning process, I generally follow at least one course, to begin with. I understand the concepts, and do some hands-on projects following the instructions...that's it, I am then ready to follow the documentation for further process. Also, the courses I choose mostly follow the project-based learning curve.

So, I would say exploring through courses isn't a trap or some tutorial hell but using these courses & not working individually to develop projects could lead to it. Yeah, get into tech, explore the paths that work for you & always be precautions about whether you are falling into these Tuturoal Hells, that's the path I'd suggest for self-taught developers & would follow the same.

Getting back to the basics, got to learn some more insights, & touched upon the basics of Solidity. For now, I am using Remix as an IDE for Solidity & the basics I've covered so far are shared below...

Solidity Basics

  • First things first, we need to specify the license identifier & the solidity version we will be using, which is quite strange but whatever...that's the first step.//
//SPDX-License-Identifier: MIT// notify compiler with version number to use...0.8.7 is specific,
//  ^0.8.7 says this & above versions to consider
// >=0.8.7 <9.0.0 greater than 0.8.7 & less than 9
pragma solidity ^0.8.7;
  • There's a keyword named contract in solidity, which obviously is used for writing smart contracts, & it is somewhat similar to the class concept in any other object-oriented programming language.

  •   contract SimpleContract{
      }
    

    Congratulations, we've successfully written our first contract & technically it's ready to be deployed to the blockchain.

  • Datatypes in Solidity:

    There's a lot of importance of bits in solidity or Blockchain development as every bit costs some value. So, for every smart contract we need to think at the bits level, & following best practices & clean code concepts becomes very important. Keeping all these things in mind, the variables come with it's bitcounts at the end, like there's an int keyword & int128, and int256, keywords too, signifying the number of bits they'll be using for them.

    1. uint: unsigned integer contains unsigned whole numbers, i.e. neither negative nor positive.

       uint256 num = 123324;
       uint8 number = 8;
      
    2. int: signed integer contains positive & negative integer values

       int128 n = 11;
      
    3. string: contains text values.

       string name = "the-third-robot";
      
    4. bool: contains true or false values.

       bool isNumber = false;
      
    5. bytes: small bit text values can be stored in bytes.

       bytes32 byteString = "thee";
      
    6. Address: stores the address of the blockchain.

       address myAddress = 0x1dA522d5B659B8b6Aee98A8110e98302AcaEbE92;
      
  • functions/methods:

    Functions/methods are used to perform/delegate specific tasks required for our contract.

      // functions/methods in solidity
      unit256 num = 12;
      function  updateValues(uint256 updatedNUm) public{
          num = updatedNUm;
      }
    

    The above function updates the defined number with an updated value.

Outro

So far all I've covered, would say just scratched the surface of Blockchain, the more I learn the more my interest increases. #MyLearnings are out & I've tried to put everything as per my understanding & there's a chance that I might've been mistaken somewhere, so, feel free to correct me on anything in the comments.

Wrapping up my Day-03 of #100DaysOfCode, will catch up again tomorrow, till then, it's a farewell.