Smart Contract: a brief introduction

Francis Chiapello - 2023-01-13

Learn what a smart contract is, how it works on the blockchain and scheduling with Solidity. An introductory guide to the world of digital contracts.

Underlying the operation of smart contracts is the blockchain.

It is now commonplace to mention the name blockchain in a wide variety of contexts, from everyday life to involving major issues of political and international value.

However, reference is often made to a technology that is poorly understood, hostile to most and surrounded by a veil of mystery. 

Index

  1. Blockchain, what is the basis of operation? 
  2. Beyond the blockchain: Cryptocurrencies and Smart Contracts
    1. How Ethereum Smart Contracts Work
  3. What languages to program a Smart Contrct?
    1. Introduction to programming with Solidity 
  4. The Future of Digital Contracts

Blockchain, what underlies the operation of digital contracts? 

The blockchain belongs to the so-called DLTs, or the Distributed Ledger Technology. These technologies put into practice the concept of ledger, i.e. a distributed ledger, and they have the following properties:

  • anonymous, the identity of participants is anonymous or pseudo-anonymous;
  • unanimous, all participants in the network agree on the validity of each record saved within it;
  • timestamped, each transaction is associated with its own timestamp;
  • immutable, each record on the chain is irreversible and cannot be changed;
  • distributed, all nodes, that is, participants in the network, have a copy of the ledger, the register, to ensure complete transparency;
  • programmable, the blockchain is programmable through the creation of smart contracts.

Centralized vs. decentralized structure

Blockchain lays its foundation in older times when people kept records of crucial information through written form in ledgers.

The latter are made up of structured data written on the basis of predetermined rules. The log can therefore be consulted and used whenever it is desired to obtain confirmation by consulting the information it contains.

Beyond the blockchain: Cryptocurrencies and Smart Contracts

All of the mentioned features are of fundamental importance for the proper functioning of a blockchain. Thanks to these features, we have witnessed the birth of the infamous virtual currencies o cryptocurrencies, first among them: Bitcoin.

The operation of digital currencies is based, once again, on the cryptography and on peer-to-peer decentralized that enable the exchange of virtual currencies between the wallets.

The main crypto coins currently in circulation are: Bitcoin, Bitcoin Cash, Ripple, Ethereum, Litecoin, Tether, BNB, Dogecoin. Other less famous ones such as Dash, Stellar Lumens, Solana.

The list could go on and on... CoinMarketCap is the most referenced cryptocurrency price tracking website in the world and currently tracks 8958 different ones.

Bitcoin was the first decentralized cryptocurrency in history. It was born primarily with the aim of revolutionizing financial transactions with the goal of making them: transparent, fast and fraud-proof.

On the other hand, however, born by Vitalik Buterin in 2013, Ethereum has revolutionized the world of cryptocurrencies by enabling, in addition to financial exchanges, the development and scheduling of digital contracts.

But this is not the only revolution of the Ethereum Foundation, which in 2022 made the transition to the validation system Proof-of-Stake (PoS): The Merge.

The real innovation is that the validator, or the miner in the Proof-of-Work, validates a new block added to the blockchain and receives as a reward the fees of the transactions contained in that block. The validator is chosen randomly from among all the nodes in the network, and his chances of being chosen increase greatly as the number of tokens he possesses increases.

The consumption of energy by PoS is glaring since the nodes in the network no longer have to compete with each other to win the tokens resulting from solving the new blocks in the chain.

How Ethereum Smart Contracts Work

Smart contracts are programs stored on a blockchain that are executed when predetermined conditions are met. Typically they are used to automate the execution of an agreement. This allows all participants to be immediately certain of the outcome, without the involvement of any third-party intermediary.

 

Smart contracts follow simple instructions to function "if/when...then..." executed by a computer network when the conditions of the contract have been met and verified. These actions could include releasing funds to the parties involved in the contract, sending notifications or issuing a ticket. The blockchain will update when the transaction is completed, so it cannot be changed and only authorized parties can see the results.

What languages to use to program a Smart Contrct?

The smart contract can be programmed by a developer, although increasingly organizations using the blockchain for business provide templates, web interfaces and other online tools to simplify the development and structure of smart contracts.

There are multiple programming languages to write a smart contract first of all Solidity. It is a high-level language object-oriented and designed to run on the Ethereum Virtual Machine (EVM). It is influenced by C++, Python and JavaScript, is statically typed, supports inheritance, libraries and complex user-defined types among other features. With Solidity, contracts can be created to manage voting, crowdfunding, blind auctions e multi-signature portfolios.

 

Other languages currently in vogue for creating and deploying smart contracts include. Vyper, created on the basis of python, Yul e DAML.

Introduction to programming with Solidity 

Below is a short code snippet in Solidity that represents a simple smart contract that can be executed on the Ethereum EVM.

Smart Contract Code Snippet in Solidity

Trust in smart contract can be better established if source code is available. Since making source code available always involves legal issues related to copyright, the Solidity compiler encourages the use of SPDX license. Each source file should begin with a comment indicating its license, and in our case the defined license è MIT, a among the most well-known open-source licenses.

La second line of code in the contract provides the solidity pragma directive which locally to the contract file itself tells the compiler which version of the Solidity compiler is to be used for source code analysis and validation against the keywords used.

Next we find the typical keyword present in many programming languages, namely constructor which generically allows us to instantiate and initialize variables that we will need during the execution of our smart contract.

The creator of the smart contract writes the message variable, of our example, the first and only time during the deployment phase of the contract itself. The value contained by message can later be varied through the call to the function setMessage by those who wish to use the contact and exchange information with it.

After the constructor has been executed, the final contract code is stored on the blockchain. This code includes all public and external functions and all functions that are reachable via function calls. 

The Future of Digital Contracts

The smart contract universe is constantly evolving and with languages like Solidity. Innovation never ceases to surprise us, and the future still promises many breakthroughs in the world of decentralized programming and of digital transactions.

Thank you for accompanying us on this adventure into the world of smart contracts and blockchain.

To further explore the world of blockchain, cryptocurrencies and decentralized technologies, feel free to follow us on the Ulixe blog.. You will find updates and insights on these fascinating topics.

Francis Chiapello

The author of this article, is ano back-end software developer, who likes to look for simple and innovative solutions. He has been working at Ulixe since 2021 and is completing his Master's Degree in Computer Engineering in Rome. In his spare time he enjoys hiking, traveling, and long rides on his mountain bike.

In the Ulixe blog talks about blockchain, cryptocurrencies and decentralized technologies.


See More Posts

background

Be My Eyes: The AI breakthrough for accessibility

Samuel Capano

background

WWDC 2024: New Libraries for iOS Developers

Pierpaolo Pignelli

background

From Ciphers to Computers: Enigma and the Cryptography Revolution.

Alessandra Bertini

Show more

Ulixe Group S.r.l. Copyright © Ulixe Group S.r.l. | Lungo Dora Pietro Colletta, 67, 10153, Turin, Italy | VAT IT03305250122 | Rea Number TO1173020