Home » Programação » What are smart contracts and how to use them in Solidity

What are smart contracts and how to use them in Solidity

Compartilhe

What’s up guys!

I’m doing a series where I’m creating a blockchain marketplace project from scratch, however as I’m doing the videos in Portuguese, I decided to write the English version.

Without further ado, let’s start our series from the basics, what are Smart Contracts?

What are Smart Contracts?

Smart contracts, are like one more stage of the blockchain, as a direct consequence of this decentralization of transactions.

The term refers to a set of immutable computational codes, which, when predetermined conditions are satisfied, become self-executing. It can establish rules and consequences for the agreed parties, without an intermediary in the transactions, such as a bank, a marketplace, etc.

In practice, smart contracts work like a normal contract, that is, they have rules, regulations, deadlines and penalties if the agreed terms are not fulfilled by one of the parties.

The difference is that they are digital, immutable and there is a computer code behind it.

But how do we apply Smart Contracts in programming? This is where the Solidity programming language comes in.

What are Solidity?

Solidity refers to a statically typed high-level language with which smart contracts for the Ethereum network can be programmed. Despite being designed for the Ethereum network, today we can use the same solidity Smart Contracts base on other networks such as Binance Smart Chain, Polygon and others.

Using solidity to develop…

The basic structure of a Smart Contract in Solidity follows the model below:

pragma solidity ^0.8.0; // sets the language version

//the contract will always be defined with term "contract" followed with name eg: SimpleContract
contract SimpleContract{
    uint storedData; //type variable value Integer

   //method set
    function set(uint x) {
        storedData = x;
    }
    
.   //method get
    function get() constant returns (uint) {
        return storedData;
    }
}

The code structure is very similar to C++/PHP/Javascript, thus facilitating the migration of those who already program in one of these languages.

With this we take our first step towards programming on the blockchain.
Knowing what is Smart Contracts and knowing the structure of Solidity, in the next articles we will start our development.