A Smart Contract is a computer logic that, given certain conditions, can enforce the execution of one or more transactions in an irreversible and decentralized way without the need for third parties. The term was first used by Nick Szabo in 1994.
Bitcoin supports smart contracts in a limited way by Turing incomplete Script language. On the other hand, the Ethereum blockchain uses a Turing complete virtual machine (the EVM) which makes the Smart Contracts essentially programs that run in a distributed way. In that sense, they are pieces of code that live on the blockchain and are executed when a corresponding transaction is sent and processed. They can read other contracts' data (if that second contract is designed for it), make decisions, send ether and execute other contracts' functions. Smart Contracts will exist and have the ability to run as long as the whole network exists, and will only stop if they run out of gas or if they were programmed to self destruct.
It is important to state that a Smart Contract is composed by different functions, and those functions will only be executed if triggered by a transaction for that purpose. Also, is relevant to mention that even if a contract’s function can call another contract’s function, the entire chain of execution has to start with a transaction signed by an EOA.
The Ethereum Virtual Machine is an emulated computer that runs a special form of machine code called bytecode, just like your computer’s CPU which also runs machine code. While it is possible to program the EVM directly in bytecode, it’s unwieldy and very difficult for programmers to read, understand, and collaborate in a low-level language like bytecode. Instead, we use a high-level symbolic language to write our program and a compiler to convert it into bytecode.
Ethereum has several high-level languages, with the compilers needed to produce EVM-executable bytecode, including (ordered by approximate age):
- LLL
-
A functional (declarative) programming language, with Lisp-like syntax. It was the first high-level language for Ethereum smart contracts, but it is rarely used.
- Serpent
-
A procedural (imperative) programming language with syntax similar to Python. Can also be used to write functional (declarative) code, though it is not entirely free of side-effects. Used sparsely. First created by Vitalik Buterin.
- Solidity
-
A procedural (imperative) programming language with syntax that is similar to JavaScript, C++ or Java. The most popular and most frequently used language for Ethereum smart contracts. First created by Gavin Wood (co-author of this book)
- Vyper
-
A more recently developed language, similar to Serpent and with Python-like syntax. Intended to get closer to a pure-functional Python-like language than Serpent, but not to replace Serpent. First created by Vitalik Buterin.
- Bamboo
-
A newly developed language, influenced by Erlang with explicit state transitions and without iterative flows (loops). Intended to reduce side-effects and increase auditability. Very new and rarely used.
As you can see, there many languages to choose from. However, of all these Solidity is by far the most popular, to the point of being the de-facto high-level language of Ethereum and even other EVM-like blockchains. We will spend most of our time using Solidity, but will also explore some of the examples in other high-level languages, to gain an understanding of their different philosophies.
Github link; https://github.com/ethpm
Repository link; https://www.ethpm.com/registry
Website; https://www.ethpm.com/
Documentation; https://www.ethpm.com/docs/integration-guide