Solidity program #1 (hello. Sol)

Solidity program #1 (hello. Sol)

The intro of solidity Programming

Hello, Amigos🙌.

#Spread your hands to stay connected let's fuel our passion🤝.

Starting from scratch in solidity, Hope this will be helpful to ignite the idea from a basic level to understand and execute a large scale.

Program 1: hello program in Solidity

Logic 1

//SPDX-License-Identifier:MIT
pragma solidity ^0.8.0;

contract MyFirstContract              // intialize
{
    string st;
    function storeinfo(string memory s) public{
       st=s;
 }
    function display() public view returns(string memory){
        return (st);
    }
}

Debugging each line:

Note:Need to provide a licensed provider i.e //SPDX-License-Identifier:MIT and mandatory to include the version we are using. for ex: here included version as pragma solidity ^0.8.0;

  • Initialized the contract as MyFirstContract

  • st is a variable of type string.

  • storeinfo() is a function name that will be helpful to store the string value.

  • display() function helps to retrieve the data stored and helps to exhibit in the output.

  • we have a few keywords such as public, view, and return. we will discuss this further.

Output or Deployed contracts (Displaying the output in Remix. ide)

Output displayed: After compiling or deploying we can find the function buttons that are helpful to execute to the user in remix. Ide online compiler for solidity.

To display multiple data using the same method

//SPDX-License-Identifier:MIT

pragma solidity ^0.8.0;

contract MyFirstContract{
    string st;
    int256 number;
    function storeinfo(string memory s,int256 n) public{
        st=s;
        number=n;
    }
    function display() public view returns(string memory,int256){
        return (st,number);
    }
}

Output or deployed contract for multiple data

Logic 2

we can reduce the code length by using the following procedure.

//SPDX-License-Identifier:MIT

pragma solidity ^0.8.0;

contract MyFirstContract{
    string public st;
    int public num1;
    function displayinfo(string memory s,int num2) public{
        st=s;
        num1=num2;
    }
}

Debugging each line:

Note:Need to provide a licensed provider i.e //SPDX-License-Identifier:MIT and mandatory to include the version we are using. for ex: here included version as pragma solidity ^0.8.0;

  • Initialized the contract as MyFirstContract

  • st is a variable of type string.

  • displayinfo() function helps to retrieve the data stored and helps to exhibit in the output.

  • Here while using the public keyword for a variable,it helps to create a getter function within the contract. with the help of using the keyword before a variable the usage of another function to display the code

Output or deployed contract for multiple data


An alternative example of a similar kind to store and display data.

Procedure 1:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Storage
{
      uint256 Myaccountno;
      string Myname;
      uint256 Mybalance;
      function filestore(uint256 ma,uint256 Mb,string memory mn) public {
          Myaccountno=ma;
          Myname=mn;
          Mybalance=Mb;
      }
      function Readfile() public view returns (uint256,uint256,string memory){
          return (Myaccountno,Mybalance,Myname);
      }
}

Output or deployed contract for multiple data

Procedure 2:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Storage
{
      uint256 public Myaccountno;
      string public Myname;
      uint256 public Mybalance;
      function display(uint256 ma,uint256 Mb,string memory mn) public {
          Myaccountno=ma;
          Myname=mn;
          Mybalance=Mb;
      } 
}

Output or deployed contract for multiple data

In the statical way of displaying the data can be as follows:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Storage{
      uint256 public Myaccountno =523478934;
      string public Myname = "Priya ranjan ch";
      uint256 public Mybalance = 500000;
}

Output or deployed contract for multiple data

Let's conclude this:

As we have gone through the different approaches to displaying the data. The code length will get reduced by using the appropriate keyword public, while initializing the variables.

I hope this will be useful for beginners to understand the syntax, functionality and overview of the Basic intro to solidity.

Further information on theoretical learning will be continued in another article lets completely climb every branch from the initial till to reach the peak.

As there is no limit to thinking, there is no limit to learning.

My intention is always to learn, discuss and grow with everyone having the same ideology.

Suggest your thoughts or views, to improve the process of learning and growing together.

#Spread your hands to stay connected let's fuel our passion. 🤝