DEV Community

Cover image for Solidity for Beginners - Day 1
Vinit Gupta
Vinit Gupta

Posted on

Solidity for Beginners - Day 1

Solidity is a programming language, yes everyone knows it(not everyone though).

But what is it for? It is actually for writing smart contracts on the Ethereum Blockchain.

Since you are here for Day 1. Let's start from the very beginning.

What is Blockchain?

If we break down the word Blockchain, it is block and chain.
It is basically a chain of blocks where each block is a Computer System that holds data.

If you don't understand blockchain, check out this article by IBM about Blockchains.

Now that we know about blockchains, there are 2 most commonly known blockchains - Bitcoin and Ethereum.

As developers, we develop our software on the Ethereum network.
And we do this using Solidity.

Solidity basics

As mentioned earlier, Solidity is just another programming language. But what are its features?
Well according to the official Solidity documentation :

Solidity is an object-oriented, high-level language for implementing smart contracts. It is a curly-bracket language designed to target the Ethereum Virtual Machine (EVM). It is influenced by C++, Python and JavaScript.

In short, it is like other languages. So, it is easy to learn.

Now, let's see some important features of Solidity as a language :

✅ Specifying the license(optional but required in editors) and the version of solidity you are writing in

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
Enter fullscreen mode Exit fullscreen mode

✅ Class based structure where class keyword is replaced by contract

contract Counter {
    //code goes here...
Enter fullscreen mode Exit fullscreen mode

✅ Statically typed language with signed and unsigned values
✅ Access modifiers : public, internal,external and private
✅ Contracts are used as objects that can be created and modified

Now, that we know the basics, let's write a simple Hello World program as always.

Counter Program in Solidity

The first and foremost step is to know the version.
I have been using Solidity 0.8.
Also, we will use the MIT license.

We will be using the Remix IDE to write our Smart Contracts.

Now the next step is to create our first class with a default value.
We will call the file : Counter.sol

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

contract Counter {
    //code goes here...
    uint public count=0;

    function incrementCount() public {
        count = count + 1;
Enter fullscreen mode Exit fullscreen mode

You can notice that I have used the uint or unsigned integer data type as counter cannot be negative.
Also, it has been set to public as we will be needing to view the value of the counter to use it.

Next is the function increment count. As known by the name, it is a simple function that increases the value of the counter variable.

If you compile this in the remix browser and deploy on the Ethereum Virtual Machine, you can view the value and increment the counter.

Kudos! You have written your first smart contract.

Follow for more upcoming articles on Solidity.

Latest comments (1)

algorithmxlabs profile image