DEV Community

ibrahim Shehu
ibrahim Shehu

Posted on • Edited on

Solidity for busy developers

This article assumes you have a prior experience in programming ..(if you know how to use variables,functions and classes then you should be good to go).

After reading this tutorial you should be able to create a simple smart contract of your choice.

According to the official documentation solidity is an object-oriented, high-level programming language for implementing smart contracts.If you are new to web3 you might be wondering what the fun are smart contracts??
What is solidity
Smart contracts are simply programs stored on a blockchain that runs when predetermined conditions are met.Note they must be self executing computer program and should be stored on the blockchain(so no single party/entity can control it).
So let's start coding in solidity 🥳.Wait!! what about IDE setup? the code editor we will be using is an online IDE called Remix but feel free to use any other editor of your choice.

  • Layout of solidity source file Solidity file ends in .sol and its required to add at the beginning file.
//SPDX-License-Identifier: MIT
Enter fullscreen mode Exit fullscreen mode

so the source code can can be made available openly.

**Variables and Data types
**

Variables

Generally there are three types of variables in solidity
which are global,local,state variables.

  • Global variables are variables built into solidity that can be accessed anywhere on the solidity source file. example includes
msg.sender, tx.origin , block.timestamp
Enter fullscreen mode Exit fullscreen mode
  • Local variables are variables that are declared in a function e.g
function name()public returns(uint){
        uint age = 24;
        return age; 
}
Enter fullscreen mode Exit fullscreen mode

Also note as declared above every statements ends with a semicolon and return types of every function must explicitly declare it return type unless it doesn't return any value.

  • State variables are variables that are declared in a contract,contracts are the solidity version of class defined by the contract keyword followed by the name of the contract.
contract Ballot {
}
Enter fullscreen mode Exit fullscreen mode

Data types

Solidity has numerous data types which are subdivided into two categories referenced types and value types.The value of value type is the actual value while the value of reference type is a reference to another value just like pionters in C++ and Go.

Type keyword Description
Adress address This is the data type for address (both contract and [EOA])(https://ethereum.stackexchange.com/questions/5828/what-is-an-eoa-account)/smart contract
Boolean bool Can either be true/false , the default value is false
Unsigned integer uint(uint8,uint16...uint256) Can take only positive integers only.It has different variant ranges from uint8 to uint256 a step count of 8
integer int Can take both negative and positive value
Array type Represent series of values
Struct struct{} Used for modelling data in solidity(Stripped version of class without inheritance method.).They can contain value and referenced types as field.
String string Hold string literal values.it is a referenced type
Enum enum Name{val_1,val_2,val_3} A user-defined data type that consists of integral constants

Top comments (0)