Become A Smart Contract Dev in 4 Minutes

Become A Smart Contract Dev in 4 Minutes

Table of contents

No heading

No headings in the article.

In this blog I am going to bridge the knowledge gap required for you to become a smart contract developer. This one is unlike most of the tutorials on the web, do you want to know how?

Introduction

Blockchain technology has created a vast field of opportunities for people. They have learnt high value coding skills and some even changed careers. The demand for blockchain developers has surpassed its supply, thus its one of the skills one should really aim at learning and capitalize on if you need to be apart of the web revolution.

What blockchain developers do is smart contract development. To get started with smart contract development you have to be well versed with what makes up an object oriented programming language(OOP).The language used in this tutorial is solidity which is the language used to build Ethereum smart contracts and deploy on multiple chains such as Binance Smart chain, Polygon or Avalanche.

Aim of the tutorial

I am going to teach you how to become smart contract developer by reading already existing project code. Most of the time you go through tutorials that guide you on the components of the solidity programming language, such as variables, types and functions. You can go through the whole loop without knowing how to connect different parts of a smart contract to make a complete DAPP.

From my experience I learnt quicker by going through already existing smart contract code, that is why I thought I should apply the same method to teach someone else. It even gets more exciting to realize you can read, understand and also implement code from existing DAPP projects.

What we are building from

The prerequisite for this type of tutorial is that you already have a grasp of the building blocks of the solidity language, but you don't need to worry i will break every piece of the code for your ease of understanding. We will start with basic code snippets to more advanced projects in this tutorial series. For this tutorial we will start with one beginner project. Our first project is a DApp for storing and retrieving data from the blockchain.

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract Pets {
    string public myPet;

    function setPetName(string memory petName) public {
        myPet = petName;

    }
    function getPetName() public view returns(string memory){
        return myPet;
    }
}

The first line tells you that the source code is licensed under GPL-3.0 The second line "pragma solidity" is where we specify the version of solidity that our smart contract is written on.

A contract in solidity is similar to class in object oriented programming languages. It is a collection of code made up of a constructor, variables, functions. 'Pets' is the contract name. In our contract we have a state variable of type string which is public and gave it a name of 'myPet'.

func.png The above line of code shows the structure of functions in solidity.Every function must begin with the keyword 'function' followed by its name 'f' ,whatever is placed inside the brackets (parameters) are the inputs ."Public view returns" states the visibility of the function that can it be accessible to the other contracts by it being 'public' and it promises not to modify the state of the blockchain with the use 'view', 'returns' implies that an output will be returned which is specified by its data type.

We also have two functions one store data and another one to retrieve data. Our first function, function setPetName() has an input of type string by the name 'petName' and it is declared public, meaning it is accessible by other contracts.'petName' is equivalent to myPet's value.The second function retrieves and return the value of 'myPet'.Test this contract code on Remix IDE,Read more on how to use Remix.Have fun by tweaking it, Create a smart contract that stores a number and retrieves it.

Hint

- Don't forget to include the license, solidity version(pragma) and start with the keyword contract.

- You'll have a state variable (uint256) to define that it is a number

- You will also have two functions one to store and one to retrieve the number.

Congratulations you are now a smart contract developer. This was just an introduction Stay tuned for more tutorials as we crack more advanced smart contract code.