Leggi questo articolo in Italiano
What is a smart contract in blockchain?
By Luca Boiardi
Smart contracts are algorithms operating on blockchain. Thanks to them, it is possible to give rise to numerous applications and platforms: let's find out about them!
How a smart contract works
The idea of smart contracts was born together with Ethereum, the first blockchain aimed precisely at the development and execution of DApps (decentralized applications). We talked about it in depth in the article dedicated to Ethereum: check it out to learn more.
The concept on which smart contracts are based is to enable automated and programmable management of value, the backbone on which all disintermediated and decentralized financial services are built.
Let’s explore and clarify how it works in this in-depth discussion.
Index
What are Ethereum smart contracts?
The first smart contracts were extremely simple and were limited to basic functions. Over time, people then began to combine them together and make them interact so that so-called DApps (decentralized applications, of which DeFi is an example) could be built.
One of the first functions performed by ethereum smart contracts involved crowdfunding and tokenization: the issuance of new tokens in exchange for a contribution, better known as ICO.
This allowed anyone to participate in fundraising for new crypto projects, while also becoming their “shareholders” (I put this in quotes because the tokens issued often gave no direct benefits, only utility on the platform of the project in question).
To achieve the goal, two blockchain smart contracts were needed : one to create the token and another to disburse it to contributors.
The smart contract to create the token contained its basic economic data such as supply (quantity of existing tokens), symbol (ticker) and name.
The crowdfunding one, on the other hand, governed its rules: the exchange rate, how many tokens need to be distributed at most, how much is the minimum below which the sale is cancelled in case of failure, and more.
Great care must be taken when creating a contract, as once it is uploaded to the blockchain it can no longer be modified (the only way is to create another one).
Simple as they were, these early Ethereum smart contract experiments laid the foundation for most of the projects that currently exist, based on the so-called ERC-20 tokens, the standard introduced by Ethereum.
Now that the elementary concepts are clear, we can move on.
"The token standard introduced by Ethereum is named ERC-20"
Smart contract and dApps
The next step was to combine several contracts with each other so as to create more complex logic. Thus was born the concept of DApps.
As the Ethereum ecosystem grew, people began to think about the first decentralized financial services platforms (the so-called DeFi). They could not be developed with only one smart contract behind them, whose functionality would have been too limited.
Therefore, different logics were thought of, achieved by combining several of them together, optimizing their execution and enabling previously unthinkable operations such as lending, cash management and collateralization.
Let us take as an example a “trivial” lending platform, such as AAVE may be. Its purpose is to connect those who have “parked” crypto liquidity to lend and those who need it and are willing to pay interest to borrow it, while also depositing collateral in the form of crypto as security.
The platform will need to know the real-time price of the coins it handles, know the collateralization rate of the loans, handle any liquidations, and change the interest rates in order to always incentivize the use of the platform. Good work. For each of these functions there is a contract that not only performs it but also communicates with others to coordinate.
Obviously, the user neither notices nor is aware of all this: the purpose is to make life easy for him and to bring as many people as possible closer to the services of decentralized finance.
Therefore, the individual will interact with a web page that, in turn, will talk to Metamask (or other crypto wallet), an interface that allows the browser to communicate with the Ethereum blockchain.
With clicks and keystrokes, the user will initialize the requested transactions, which will be forwarded to the smart contracts and executed.
The user will then get feedback on what he or she has just executed. Staying with the lending example, he will know how much liquidity he has deposited, how much he is earning, etc.
Be careful, however, because we are not limited to the world of finance: smart contracts allow NFTs marketplaces such as OpenSea to exist, for example .
"The DApp concept, the heart of DeFi, comes from the combination of several smart contracts"
How do smart contracts eliminate intermediation
Smart contracts are algorithms that run on blockchain. They are programmed to perform a wide variety of functions, designed to work without any human intervention.
Therefore, a smart contract, or an application formed by a plurality, moves autonomously and eliminates any kind of intermediary, precisely because there is no need for humans in this procedure.
How do you develop a smart contract?
Creating a smart contract requires in-depth programming skills, which are essential to succeed in the venture.
In any case, there are guided tutorials available on the Web that enable the creation of simple smart contracts, which are very interesting for anyone curious about this technology.
Smart Contract, DApp and Security
As the complexity of DApps increases, so does the risk of bugs and unwanted behavior.
Ethereum smart contracts are written in Solidity, a language called Turing Complete. Translated: it can be programmed to do almost anything.
As a result, it becomes difficult to formalize its security and ensure that the DApp will not have any errors or vehicles that can be used maliciously to harm users.
Thus auditors are born, whose job is to examine the code and find any flaws.
As for what was said just now, not even one audit guarantees complete security on a smart contract, which is why more than one is often done. As in anything, you are never totally safe from the unexpected.
More than the number of audits received, the security of a DApp depends on its history and longevity. Indeed, if it manages high capital and has been doing so for a long time without ever having been hacked, it is much more likely to be secure. However, we reiterate with certainty that zero risk, at least for now, does not exist.
Let us also not forget the importance of privacy and security from malware and other network threats. On this, Nord VPN can come to our rescue.
Final considerations
To conclude, we can say that a smart contract is an algorithm executed on blockchain that receives specific inputs, processes them according to the rules it contains, and eventually returns outputs.
Compared to a classic computer program, the differences are obvious:
- What technology are smart contracts based on? It is the blockchain that is the protagonist, as well as the most notable diversity from traditional software.
- The first is that the inputs and outputs of a smart contract are financial transactions on blockchain containing data and cryptocurrency.
- In addition, execution is decentralized: there is no central server on which the program runs, but it is distributed over a multitude of nodes.
- Finally, Ethereum has a programming language created specifically for smart contract development, called Solidity.
Anyone can write a contract and upload it to the Ethereum blockchain. Once done, it can no longer be modified or deleted, and will forever execute the commands programmed into it, or at least as long as it receives the necessary interactions as input.
Smart contracts have enabled everything we now know as DeFi, one of the biggest innovations not only in the cryptocurrency industry, but undoubtedly also in technology and finance.