Day-04: Solidity Insights #100DaysOfCode #MyLearnings

Day-04: Solidity Insights #100DaysOfCode #MyLearnings

·

4 min read

Intro

I just got to know that Solidity is an object-oriented language...I mean I was aware but you gotta google it to confirm, that means I'll need to learn the object-oriented concepts again with Solidity which is not that difficult compared to learning it for the first time. I'll learn it if need be, but following & completing the course is more important at this point.

Previously I've completed the basics from contracts, basic datatypes & function-like concepts & moving ahead obviously comes with some more advanced concepts like data storage, arrays, mappings & more. So, without further ado, let's dive into it,

Concepts Covered

  • Sharding:

    • As we know users need to pay extra fees for their transaction to be considered in the priority list, but when the participating users increase infinitely then the gas limit will eventually reach infinite & the solution eventually becomes non-scalable.

    • To resolve this problem Shrading comes into the picture, in short, it’s called the blockchain of blockchains i.e. there will be a main chain that will be managing everything and anything & the other connecting sub-chains will poke into the main chain as and when the time comes.

    • This means there are more chains for people to run transactions on effectively increasing the block space that there is.

    • Sharding greatly increases the number of transactions on layer one of the blockchain.

  • Layer one blockchain solutions:

    • Any base layer implementation of blockchain

    • E.g.: Bitcoin, Ethereum, and Solana are layer-one blockchains.

  • Layer two blockchain solutions:

    • Any applications added on top of layer one

    • E.g. chainlink and other solutions.

  • Any time you make any change on a blockchain including making a new contract, it happens in a transaction. Deploying a contract is also a transaction.

  • Access Modifiers: Function visibility specifiers

    1. Public: Visible externally and internally of contracts.

    2. Private: Only visible in the current contract.

    3. External: Only visible externally.

    4. Internal: Only visible internally i.e. within the contract & its descendants.

  • Pure Keyword: pure modifier allows read-only values & within the scope only. Also, it doesn't cost any gas unless called within the code.

      // pure
      function noGas() public pure returns(uint256){
      return 1 + 1;
      }
    

  • View Keyword: view modifier only allows to read values for functions, & doesn't cost any gas unless called within the code.

      // view
      function noGasRequired() public view returns(uint256){
      return num;
      }
    

    The comment "Costs only applies when called by a contract" signifies that the function will cost any fees only when called by a contract i.e. within the code function call.

  • Struct:

    Struct is used to define the data schema that we want to use further.

      // struct
      struct People{
      string name;
      int256 favouriteNumber;
      }
    
  • Arrays:

    As we are all aware, arrays store a list of values & follow zero-based indexing. Also, we can define arrays of constant length & dynamic length as well.

      // Array
      // People[10] public people; => array of fixed length
      People[] public people;
    
  • Mappings: It's a Map Data Structure & works in key-value pairs.

      // mappings
      mapping (string => int256) public favValues;
      function addPeopleToMap(string memory id, int256 favNumber) public{
      peopleMap[id] = favValue;
      }
    
  • Memory Storage & Call Data:

    Data can be stored at 6 places in the blockchain & mostly needs to be set while adding function parameters.

    1. Memory: Exists temporarily at the time of particular function calls.

    2. Storage: stored permanently

    3. Call data: Exists temporarily at the time of particular function calls, variables assigned to Calldata storage cannot be modified

    4. Stack

    5. Code

    6. Logs

We can only define memory, storage & call data & are required in the case of struct, mapping & arrays. In all other datatypes, the storage location is set by default.

Well, with all the concepts the last thing I did was to deploy the contract I've developed on Sepolia Testnet. No matter how many techs you learn, the first deployment experience always feels like some sort of achievement.

Outro

So far these are some of the learnings that I can share with you all, I've tried to put everything as per my understanding & there's a chance that I might've mistaken somewhere, so, feel free to correct me on anything in the comments.

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