Storage.sol smart contract explained in Remix IDE

In this tutorial, we will understand the working of one of the simplest contracts in solidity which is a default contract in Remix IDE.

Above you can see the storage.sol contract. let’s discuss in detail about it.

pragma solidity >=0.4.22 <0.7.0;
At line one we define the version of solidity which we will be using in this contract by using the ‘pragma’ keyword. Here version must be greater than or equal to 0.4.22 and smaller than 0.7.0.
Without defining the version you will get the error in IDE.

/** * @title Storage * @dev Store & retrieve value in a variable */
Comments as usual in every language. (Noting new) 🙂

contract Storage {
In solidity, we define the contract using the ‘contract’ keyword. It is the same as you define a class in java using the ‘class‘ keyword, forwarding contract name i.e. ‘Storage‘ in above contract.

uint256 number;
At line number nine we have defined an unsigned integer type variable which is of 256 bits in size naming ‘number‘.

Besides this, we also have a string, bytes, int, address, bool variables in solidity, and which can be of size 8, 16, 32 … up to 256 bits.

function store(uint256 num) public {
number = num;
Now we define a function named ‘store‘ it takes ‘num’ as a parameter which is of type uint256. This function is a public function i.e. can be accessed publically or by anyone.
Inside the function body, we are assigning the value of num to the global variable (storage variable in case of solidity) ‘number‘.

function retrieve() public view returns (uint256) {
return number;
Here is another function name ‘retrieve‘ which is also a public function. It does not take any parameter as input but returns a uint256 type of value.
Note: uint256 or uint both are similar.
The above function is of ‘view‘ type mean it does not update the state of the contract i.e. it does not update variables defined in the storage space i.e. ‘number‘ in this case, although it’s just returning the value stored in variable ‘number’.
In the body, we just return the number variable as defined in the function’s declaration.

Now, fire your Remix IDE and try to run the contract.