What Is An Ethereum Smart Contract?
August 29, 2022
11 min
What are smart contracts? They consist of software built on the blockchain with the goal of automating and decentralising any kind of application. Decentralised applications created through these codes are called DApps forshort. They form the basis of Decentralised Finance (DeFi) and Web3. In this article, we will explore how smart contracts were invented and how they work. Let’s find out about the evolution oftechnology up to Ethereum smart contracts and project ourselves into the future: will smart contracts replace traditional contracts?
What are smart contracts?
Rules are fundamental to maintain stability in any human society. That is why contracts are drawn up: a guarantee that agreements will be respected by the parties involved. However, the effectiveness of traditional contracts is not immediate. Terms and conditions pass through a bureaucratic circuit of intermediaries (the contractors themselves, lawyers, judges, notaries) before coming into force, being modified or being enforced. This results in an often slow and cumbersome contractual process, sometimes through an arbitrary interpretation of the contract itself.
The agreements recorded in smart contracts, on the other hand, automatically generate logical consequences when stated conditions occur. In a nutshell, smart contracts define a series of cause-effect chains based on ‘if… then‘ formulations. For example: “IF I pay my rent on the first of the month THEN the landlord lets me use the flat for the month”. So, in essence, how does a smart contract work? Firstly, one of the parties involved in the agreement generates a transaction (if…), such as sending a certain amount of cryptocurrency, or transmitting information. This transaction is taken over by the reference smart contract which, by evaluating it in compliance with the rules, in turn generates one or more transactions (…then). The result could be the sending of funds to the second party involved in the agreement, or the unlocking access to a real-world object, such as a flat in our example above.
These ‘contracts’ are ‘smart‘ because they deliver results in an optimal manner. Reducing the arbitrary influence of the mechanism regulating the relationship between the parties is essential. Moreover, such a contract is ‘smart’ not because it is ‘rational’, but because it does not allow for exceptions or interpretations, acting in a planned and predetermined manner.
So, what is a smart contract? Essentially, it is a piece of software developed and executed on the blockchain, composed of codes that define the rules for the operation of the program itself. In fact, smart contracts have the same characteristics as the technology behind cryptocurrencies:
- Immutability: once created, smart contracts cannot be changed. Just like the blocks containing Bitcoin transactions, they cannot be ‘rewritten’.
- Decentralisation: smart contracts are distributed among all nodes belonging to the network of a blockchain. As we have said, when activated, smart contracts generate transactions. Nodes must reach a consensus on the validity of these resulting transactions before registering them in the blockchain. Therefore, each node individually repeats the request process to the smart contract, in order to evaluate its response. If most nodes receive the same response, then the transaction is considered valid. This is possible because each node keeps a copy of the code of all smart contracts.
- Trustless: the consensus reached by the nodes on the consequences of an agreement is sufficient to make a smart contract effective. The parties interacting through it do not need to trust each other, let alone an intermediary.
- Transparency/privacy: smart contract codes, being hosted on a blockchain, can be accessed by anyone. This complete transparency, however, does not sacrifice privacy: users using smart contracts retain their anonymity, because they identify themselves with their wallet addresses or cryptographic keys.
To fully understand what a smart contract is, we still need to delve into the reasons behind their creation in the crypto world. Why is the automatic execution of immutable and distributed software necessary? Let’s find out by reconstructing the history of smart contracts: from the origin of the concept to its first successful implementation on Ethereum.
The history of smart contracts: from Nick Szabo to Vitalik Buterin
Who invented smart contracts? The form in which we know them today is the fruit of Vitalik Buterin, the creator of Ethereum. However, the origin of the concept predates him. It was Nick Szabo, in fact, who coined the term ‘smart contract’, defining it in 1994 as “a computerised transaction protocol that executes the terms of a contract.” He is also a possible candidate for the identity of Satoshi Nakamoto.
The creator of Bit Gold, a decentralised currency based on cryptography and the Proof-of-Work consensus mechanism (just like Bitcoin) lists the possible advantages of smart contracts in the same document as above. First of all smart contracts promote a reduction of contract execution costs as well as dependence on intermediaries. They also promote the creation of new business models and social institutions. In fact, Szabo suggested the creation and exchange of synthetic assets, and the transfer of ‘voting rights’ through smart contracts: the latter function has actually been implemented in DAOs, as we will see later, just as the issuance of derivative tokens is now common in DeFi.
The evolution of the concept therefore led us to its first modern version: Ethereum Smart Contracts. Vitalik Buterin‘s blockchain implementation put Szabo’s idea into practice. The code of Ethereum was in fact designed to go beyond the peer-to-peer (P2P) value exchanges of Bitcoin. The goal was to create software for any decentralised application, precisely through the mechanisms of smart contracts.
In order to create a true Decentralised Finance Ecosystem (DeFi) and more generally, all the products and services we now recognise as part of Web3, it was necessary to replace traditional third parties with code programming. Smart contracts should automatically lead to the predetermined results, without human intervention. This is a complex goal, because at the time, these programmes had to respect the characteristics of the blockchain, listed above, and be relatively ‘simple‘ to create. In short, there was a need for a standard language understandable to all developers, as well as a shared environment hosting all the ‘rules‘ of smart contracts. Ethereum has been equipped with both: let’s discover Solidity and the Ethereum Virtual Machine (EVM).
Solidity and EVM
Gavin Wood, one of the founders of Ethereum as well as Polkadot, suggested the programming language for Ethereum smart contracts: Solidity. Its ‘curly brackets’ syntax is derived from C++, the language in which Wood initially implemented the Ethereum whitepaper. It supports reusable code libraries, i.e. standard functions that can be called up by each smart contract.
The smart contracts are written in the Solidity language, but to be used, they must be executed on the Ethereum blockchain. To do so, they are ‘compiled‘, i.e. translated into bytecode: a sequence of commands, called OP CODE. These instructions describe step-by-step operations carried out by the Ethereum Virtual Machine (EVM): the environment in which all smart contracts are executed. Imagine it as a ‘world computer‘ capable of supporting any kind of programme as long as it has sufficient time and space. Vitalik Buterin has also described the EVM as a ‘Swiss army knife‘, a set of tools (software) and rules that can be used for any potential need.
In fact, this was the goal behind the creation of Ethereum: to decentralise every service and provide it through blockchain technology. A real commitment, because today the most widely used decentralised applications (DApps) can be found on Ethereum, alongside the largest Decentralised Autonomous Organisations (DAOs) So, what are DApps and what is a DAO?
What are DApps and DAOs?
What differentiates DApps and smart contracts? Quite simply, DApps are applications built on the blockchain, whose functions correspond to different smart contracts. They are a set of codes for a wide variety of use cases: finance, gaming, social networking and beyond for example.
Bitcoin’s protocol for the p2p exchange of cryptocurrencies may in fact be the first crypto DApp. However, the most accurate representation of the concept comes from the same paper by Nick Szabo as mentioned earlier. Dapps are similar to vending machines, which provide products and services in exchange for the right number of coins. So, by sending cryptocurrencies, or often just paying a fee (gas fee), you can take advantage of the functions of a smart contract: let’s look at the DApp examples mentioned to better understand the concept.
- Finance: there are Ethereum DApps for decentralised lending, such as Aave, and decentralised exchanges (DEX) for exchanging crypto tokens, such as the Uniswap DApp. If you want to learn more about smart contracts and DApps, the founders of these projects, Stani Kulechov and Hayden Adams, have interesting stories to discover.
- GameFi: the video game Axie Infinity was made on Ethereum, an example of DApp Game Finance.
- Social Networks: the project of a Web3 social network can still be credited to the founder of Aave, although it is not the first example (Steemit and Voice, for instance). Essentially, it is a DApp similar to Twitter, but based on tokens and smart contracts: the Lens Protocol.
Moreover, smart contracts can also support social functions: Decentralised Autonomous Organisations (DAOs) bring together the holders of a certain cryptocurrency on a virtual platform. They are thus entitled to vote on issues of interest to the DAO. The right to vote is the basis for all governance functions and it is made possible via smart contracts. This could concern the treasury management of a project, the proposal and implementation of protocol updates, the definition and modification of the roadmap and much more. The DAOs of UNI and AAVE holders are also hosted on the Ethereum blockchain, but there are also other examples: Yearn Finance (YFI), Ethereum Name Service (ENS) and Compound (COMP). All reference tokens are also issued by a particular type of smart contract standard native to Ethereum, the ERC-20.
The Future of Smart Contracts
Smart contracts seem to be the ideal solution for decentralising Web3 services and applications in DApps, but they also have limitations. First of all, as smart contracts are written by humans, it is possible that they contain errors. The codes need time to be reviewed, then audited. The security of blockchain technology, as well as the DeFi derived from it, has yet to be properly tested.
Finally, programming variability and randomness, characteristics of the real world, are extremely complex. Smart contracts do not yet have enough ‘flexibility‘ to include the human factor. Integration with oracle technology (Chainlink) brings real-world events and information onto the blockchain, just as Artificial Intelligence (AI) can analyse smart contract processes to optimise them and make useful predictions. Nevertheless, creating software to manage the infinite facets of human behaviour remains extremely difficult. This puts blockchain at a disadvantage compared to traditional centralised solutions. We will still rely on judges and lawyers to resolve complex disputes, but perhaps one day smart contracts will be able to clarify everything through strings of code.