Blockchain

Single Inheritance in Solidity Programming Language | At A Glance! | Blockchain | Ethereum Program



๐Ÿš€ Dive into the world of smart contract development with our latest video tutorial! In this in-depth session, we unravel the intricacies of implementing single inheritance in Solidity, building the foundation for robust and efficient smart contracts. Whether you’re a seasoned developer or a blockchain enthusiast, this tutorial caters to all skill levels.

๐Ÿ› ๏ธ We take you through each step meticulously, explaining the core concepts of single inheritance and its significance in Solidity programming. Our example-driven approach ensures that you not only understand the theory but also witness its practical application. The tutorial is designed to be beginner-friendly, making it accessible to those just stepping into the world of blockchain development.

๐Ÿ”ง Using Remix IDE, we demonstrate how to seamlessly write, deploy, and interact with your smart contracts. From setting up your development environment to debugging, our tutorial covers every aspect to empower you with the skills needed to excel in Solidity.

๐Ÿ’ผ This tutorial holds immense value for students and professionals alike, as the showcased program is a frequently asked question in previous year papers, often carrying substantial marks. Gain a competitive edge by mastering this essential topic that combines theoretical knowledge with hands-on coding experience.

๐ŸŒ Don’t miss out on this opportunity to level up your Solidity skills and build a strong foundation in blockchain development. Subscribe now for a guided journey through single inheritance in Solidity, accompanied by a practical example that demystifies the complexities of smart contract programming.

๐ŸŽ“ Topics Covered:

Single Inheritance in Solidity
Practical Implementation
Remix IDE Walkthrough
Debugging Techniques
Frequently Asked Question in Exams

__________________________________________

๐Ÿ”€ Sorting: https://youtube.com/playlist?list=PL9jefoqM2f-P6Ehn7ZtK9OXFZAuWHUiI1

๐Ÿ” Searching Algorithms: https://youtube.com/playlist?list=PL9jefoqM2f-PjhGvQrx3srOa5iIs4gIDY

๐Ÿ”ข Arrays in Python: https://youtube.com/playlist?list=PL9jefoqM2f-P0BHa_mjkNm-lvvPMqb9cE

๐Ÿงฎ White Box Testing Numerical: https://youtube.com/playlist?list=PL9jefoqM2f-Mhk8fhrqqIhtXSqFzFMCr7

๐Ÿ“ˆ Big Data Analytics: https://youtube.com/playlist?list=PL9jefoqM2f-MUTHq5_1jYm9XOMS3VHTvb

๐Ÿค– Deep Learning: https://www.youtube.com/playlist?list=PL9jefoqM2f-PSPzQe6DuSeUTtGAftQz7B

๐Ÿ”— Blockchain and DLT: https://www.youtube.com/playlist?list=PL9jefoqM2f-NPuxHKBNilP6k8FHZ9RYLf

โค๏ธHeart Disease Prediction using Machine Learning Project: https://www.youtube.com/playlist?list=PL9jefoqM2f-OMXLVcBVk4YxX7AyrgMDYI

๐Ÿ Python Small Projects: https://youtube.com/playlist?list=PL9jefoqM2f-PpdCKjwuWoiDctQcUKeR6S

Subscribe to At A Glance!

Buy me a coffee: https://www.buymeacoffee.com/ataglanceofficial

Join Telegram: https://t.me/ataglanceofficial

Official Website: https://ataglanceofficial.netlify.com/

Follow me on Instagram: https://www.instagram.com/at_a_glance_official/

__________________________________________

Hello everyone welcome back to my YouTube channel in this particular video we’ll be looking into one of the most frequently solidity programming question so basically the question is to implement single inheritance from scratch now when we talk about inheritance inheritance is nothing but passing on the parent class

Characteristics or features in to the child class so that we don’t have to write multiple times the same code it promotes code reusability now in this particular case we’ll be specifically looking how we can build single inheritance now for those who don’t know what single inheritance is in single

Inheritance there is one single parent and one child included the parents characteristics or features that are present inside the parent contract will be passed on to the child contract now you can think of contracts similar to classes in object oriented programming so without further delay let’s start building this particular

Code now whenever we write solidity programming code it’s best practice to include the license identifier here we are using spdx that is software package data exchange license identifier and specifically we are using the GPL 3.0 license now make make sure this is commented and we use double slashes for

Comments in solidity language now this is a compulsory statement we have to include this pragma directive so basically this particular line says that the further code is written in solidity language and with that we also have to mention the version so over here you can see the version is

0.810 so let’s start building the code so as you know that in solidity we build contracts so let’s build contract so the basic idea is we are going to build a code in which the parent contract will be the dimensions of a rectangle that we are going to set and inside the child

Contract we are going to calculate the area from that particular Dimensions which are set in the parent contract finally we’ll be building one more contract which is just for testing the two contracts that we have created before so that we be able to understand how this single inheritance is working

So let’s build the parent contract that is rectangle Dimensions now inside this I’m going to declare two variables so basically here I’m declaring unsigned integer this is a keyword for declaring unsigned integer after that I’ll be specifying the name after that I’ll be writing the x specifier that is intern internal access

Specifier is nothing but it will allow whatever variables we are creating over here it will be accessible inside this particular contract as well as in the child contracts too wherever this particular contract will be inherited now after that we’ll be writing the name of the variable that is a and we’ll

Assign the value 10 similarly we’ll be assigning one more variable that is B and this time we give it a value of 20 now we are done with the assignment of variables now make sure that this particular variables are called as state variables this will be stored inside the contract

Storage now after this we’ll simply Define a function Now function can be defined with the help of the keyword function and then we’ll specify the name of the function so we’ll write the name of the function as setting Dimensions here we are just going to return the values of this particular two variables

That we have declared so there will be no list of arguments required for this particular function after this we’ll be writing one keyword called as view now while we are writing this particular keyword because in this particular function we are going to return the values of the variables A and B now

These variables are stored inside the contract storage which is present in the ethereum blockchain on a particular address so whenever we have to access the variables that are declared inside the contract storage we’ll have to use this Variable View so that we can view the variables in the contract storage

Now after this we’ll Define the axis specifier external we are defining external over here so that this particular function can be quable in the inherited contracts that that we are going to build afterwards so that is why we have declared external exess specifier now after this we’ll be

Writing the function returns now this will specify what exactly we are going to return in this particular function so inside this since we are just going to return the values of these two variables so we’ll be writing the data types of these two variables

That is u in and since there is one more variable so we’ll write U so we just have to specify the data types in this particular returns function and that’s it now we are good to go for writing the body of this particular function now inside this we just have to return we

Values of these two variables now in solidity if we want to return more than one values we cannot directly write it like this because we can return value one at a time if we are writing it like this so whenever we want to return more than one

Values together so we have to use tle structure so these two will be return together so now you can see we are done with this particular parent contract now similarly we’ll be defining the child contract now inside parent contract what we have done we just have declared these

Two variables and we have simply returned that particular values of the variable by declaring a function that’s it now let’s define one more contract the name of this particular contract will be area because the main Moto of this particular contract is to calculate the area of the rectangle whose

Dimensions are set in the parent contract now obviously l in this particular contract we don’t have the values of A and B right that values are present inside rectangle Dimensions contract so we have to access this particular contract so for accessing this particular contract we have to use

A keyword named is do you want to check out this attractive funny memes then what are you waiting for these are just a glimpse of the memes that I have created on my Instagram page you can find the link to my Instagram handle in the description box please visit the

Link link and do watch all these interesting funny memes these are not just memes these memes and reals contains technical information here I try to relate memes with the technological Concepts so please do appreciate that by watching all those and if you love it please hit the follow

Button after this keyword we’ll have to write the name of the contract which has to be inherited in the child class now by simply writing this particular small code the features that are inside this particular contract are inherited inside this child contract now we’ll simply Define one function the name of the

Function will be calculate area so basically this function is just going to calculate the area of the rectangle so there will be no parameters required for this particular function because we are getting the variables from the parent contract only after this particular name of the function we’ll Define external

Again because we we again want this particular function to be accessed outside this particular contract that we are going to Define after some time next we’ll write the view keyword because we are going to look at the contract storage variables that is a and b after this we’ll be

Writing returns keyword and inside this we’ll just write U because we are just going to return the area after calculating so now we are good to go for writing the body of this particular function now as you know the area of the rectangle is just the multiplication of

The two Dimensions that are present inside it so we’ll write return a multili b that’s it so this particular thing will return the calculated area of the dimensions that we have set earlier in the parent contract now this is your single inheritance you can see the parent contract characteristics are inherited

In the child contract now just to make you understand whether this particular code is working we will be creating one more contract this contract will be just for testing purpose so we can just write the name of this particular contract as callar and then inside this particular

Contract we be we’ll be creating object of the child class because we want to access things from Child class so we’ll define object of child class so for defining the object we just have to write the contract name and after that we have to give the name of the object

After that we are going to use the new keyword which is going to create a new object and we again have to write the name of the contract so this will create object of the area contract now we’ll simply Define one function named Let’s test this particular function won’t take

Any parameter and this time this particular function is public by default it is public only next we’ll write view because we are again going to look at the contract storage and then we are going to write this particular returns keyword inside this we’ll write u in because this particular function again

It is going to return the area now inside this we will be returning the object with the function calculate area called with it so we’ll write obj and then once we write dot after it you can see these two methods are actually accessible calculate area and setting

Dimensions you can see setting Di iions is present inside the parent class but still it is accessible now this is because we have inherited it but now we only want the calculate area because we just want the area so we will be writing the name of the function

That is calculate area and then this is done so you can see we have also created a colar contract which will simply create an object of this particular child class and it will call the method inside it now we are done with this particular code so let’s try

To deploy it so over here you can see we have successfully compiled it with a green tick now we’ll try to deploy it so over here you have to select the name of the contract that you have to deploy so here I’ll be deploying the Coler contract because inside the color

Contract I have created the object as well as this particular object has called the function present inside the area contract which will perform the task so let’s uh take this particular contract and then we’ll deploy it so now you can see it has successfully got deployed and we have this particular

Contract and inside this we can see we have the function Let’s test so let’s try to click this and you can see we have got the value 200 so if you calculate we have 10 as the First Dimension and 20 as the second dimension 10 * 20 gives us 200 so it’s working

Nicely so I hope it is clear how we can write the code for single inheritance in solidity language I hope this particular code is clear to you all if you guys have any single doubt that you can straight away put it in the comment section I’ll be happy to solve it for

More such videos do like share and subscribe to my channel also hit the Bell icon and don’t forget to follow me on Instagram thanks for watching have a good day ahead

Write A Comment

Share via