Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 21, 2022 07:48 pm GMT

Guide for Smart contracts in Solidity

You might heard people in web3 and blockchain talking about smart contracts and solidity.

What even is a smart contract

In Solidity, smart contract can be considered as collection of constructor, functions and state variables, or to be more beginner friendly we can take contracts as a class in c++.
In a smart contract, we can implement any algorithm or whatever you want to be done once your contract is deployed or compiled.

here is a quick tutorial of the same:

1. Constructor

Sometimes we want some variables to be declared as soon as our contract is deployed or compiled. So to achieve this we have constructors. These are initialised with a constructor keyword.
constructor() {}
Since constructor is just a function that is run on contract creation, you can define or write code for initialising the contract.

2. State variables

General variables where we store the state about our contract.

3. Functions

You must be knowing what functions are if you're familiar with any other programming language. If there is something or some block of code that is to be run different times on many places, you can define those code lines in a functions and call that function to run them.
Same applies in Solidity.

contract my_contract{   uint num_1 = 10;   uint num_2 = 20;   function add(uint a, uint b) public pure returns(uint){      return a + b;   }}

But here's a thing to know in solidity is that if in a contract you declare a function and doesn't put any implementation inside it, our parent contract will become an abstract contract. So our contract will look like this.

abstract contract my_contract{   function add(uint a, uint b) public virtual returns(uint);}

As you can see above, our contract my_contract has a function add that is not yet implemented, so we have marked our contract as abstract contract.

_I hope this topic was clear, thanks for reading!
Do checkout the video in the blog that describes the same.
_


Original Link: https://dev.to/seek4samurai/guide-for-smart-contracts-in-solidity-56l4

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To