HomeWikiDApps & Smart ContractsEthereum: how do smart contracts work?

Ethereum: how do smart contracts work?

Smart contracts are the main feature that has made Ethereum so successful. 

What are smart contracts and what are they for

The Bitcoin protocol does not provide for the possibility of creating truly complex smart contracts, because it was basically designed only to enable transactions. 

In contrast, Ethereum, which was born 6 years after Bitcoin, was designed from the outset to be basically a network capable of hosting and executing smart contracts

In 2014, Ethereum co-founder Vitalik Buterin wrote explicitly in the whitepaper that the network he was designing was a next-generation platform based on smart contracts, and that alternative applications to Bitcoin based on blockchain technology also included the use of digital assets to represent custom currencies and financial instruments, non-fungible assets and more complex applications. 

In particular, the latter, i.e. smart contracts, were defined as applications involving direct control of digital assets by a code that implements arbitrary rules, or decentralized autonomous organizations based on blockchain, so-called DAOs.  

Vitalik wrote: 

“What Ethereum intends to provide is a blockchain with a built-in Turing-complete programming language that can be used to create ‘contracts’ that can be used to encode arbitrary state-transition functions, allowing users to create any of the systems described above – as well as many others that we have not yet imagined – simply by writing logic in a few lines of code”.

Thus, smart contracts on Ethereum are lines of code by which it is possible to program the automatic execution of instructions by the network, when certain conditions are met, without having to entrust their execution to an intermediary.

In fact, Buterin himself put the term “contracts” in quotation marks, because rather than real contracts between parties, they are computer programs executed by a decentralized network. 

From a general point of view, therefore, their operation is not very complicated. 

smart contract
Smart contracts are executed once the conditions contained therein have been verified

Deploying smart contracts on the Ethereum blockchain

First of all, one or more developers must obviously create the smart contract by writing the appropriate lines of code, and then they must send it to the Ethereum network. 

In technical terms, publishing it on the Ethereum blockchain means making all the nodes in the network receive and execute it. Once published, all instructions in it will always be executed by all nodes in exactly the same way. 

Therefore, not only its publication but also the execution of instructions is irreversible once it is published on the blockchain. 

Therefore, what really matters are the instructions it contains – which can be the most diverse – and how many people use it. Indeed, in order for the instructions of a smart contract to actually be executed, there must be one or more transactions that invoke them

It is also worth remembering that these instructions generally involve the use of resources, such as data or tokens, so for them to actually be executed, all the conditions set as necessary must be met. 

Sometimes this data comes from outside, thanks to so-called oracles, while sometimes it simply comes from transactions on the blockchain. 

Usually, the transaction that triggers the execution of the instructions contained in a smart contract involves the payment of a fee in ETH, and in many cases in order to actually trigger the execution also involves the payment or sending of tokens specific to the smart contract itself, or other smart contracts. 

Technically, smart contracts are a type of account on the Ethereum blockchain, “controlled” by the network rather than a central entity. They can store ETH or tokens, and can also send transactions on the network autonomously.

How to interact with the code and more generally with dApps

Users can interact with smart contracts by sending transactions that trigger one of the functions defined within their code. 

Therefore, the functioning of smart contracts on Ethereum is generally very simple: just send a transaction of a certain type to a smart contract, and this will trigger the execution by the nodes of all the instructions contained in the function of the smart contract invoked by the transaction itself. 

Obviously, depending on which instructions are contained in the function invoked, very different consequences can be generated, varying not only from smart contract to smart contract, but also from function to function. 

The enormous complexity of smart contracts therefore derives precisely from what the individual smart contracts do, and not in general from the fact that the Ethereum network supports and executes them. Moreover, it is absolutely impossible to list how all types of smart contracts on the network actually work. 

Marco Cavicchioli
Marco Cavicchioli
Born in 1975, Marco has been the first to talk about Bitcoin on YouTube in Italy. He founded ilBitcoin.news and the Facebook group" Bitcoin Italia (open and without scam) ".
RELATED ARTICLES

Stay updated on all the news about cryptocurrencies and the entire world of blockchain.

MOST POPULARS