Ethereum Smart Contracts
What are smart contracts?
In the 90s, Nick Szabo coined the term "Smart Contracts" when describing the notion of a digital protocol designed to facilitate, verify, or enforce the terms of an agreement without the need for a third party. The full possibilities of this protocol became a reality when blockchain technology emerged. Similarly to a vending machine, smart contracts work by following simple "if/when...then..." statements that are written into code on a blockchain, meaning with the right inputs, a certain output is guaranteed. The terms of a smart contract are specified in code, thus eliminating the need for human intervention, intermediaries or a central authority. Smart contracts are immutable: their definition (bytecode) cannot be changed or updated once they are deployed on the blockchain.
They are often associated with the Ethereum blockchain, the world's second-largest crypto by market cap, that was designed to accommodate smart contracts, but the idea isn't restricted to any particular platform or blockchain network. Every blockchain uses different templates, algorithms and encoding techniques.
Why Ethereum smart contracts?
While Bitcoin (BTC) was the first cryptocurrency to support basic smart contracts, Ethereum smart contracts are more popular, replacing Bitcoin's more restrictive language with language that allows developers to use the blockchain to process more than cryptocurrency transactions.
On the Bitcoin blockchain, only the owner of a Bitcoin private key can produce a digital signature proving that they own the cryptocurrency they claim to own. In contrast, ETH has developer-friendly languages for writing smart contracts such as Solidity. The Ethereum network is "Turing-complete," meaning it supports a broader set of computational instructions. Without limits, programmers can write just about any smart contract they can think of.
Smart contracts are the fundamental building blocks of Ethereum applications. Ethereum smart contracts have led to the network's array of decentralized applications (DApps), DAOs, new technologies and other use cases such as NFT marketplaces that enable buying and minting digital assets like collectibles, art, music and even access to real-world items.
How do Ethereum smart contracts work?
Any user or application is free to join the network and submit transactions, which are later broadcast to other nodes for validation and execution, but you must have some of Ethereum's digital currency (ether) in your Ethereum wallet (for example Metamask) to deploy Ethereum smart contract on the network. A wide selection of tutorials, tools and development frameworks is available here.
Unlike most blockchain networks which are described as a distributed ledger, Ethereum is what's considered a distributed state machine, containing what's known as the Ethereum Virtual Machine (EVM). This machine state, which all Ethereum nodes agree to keep a copy of, stores smart contract code and the rules by which these contracts must abide. Since every node has the rules baked in via code, all Ethereum smart contracts have the same limitations.
Smart contracts are public on Ethereum and can be thought of as open APIs. The creators of Ethereum added an important feature to the blockchain: the storage, which could be easily described as a single GitHub repository.
Solidity is an object-oriented and static programming language influenced by C++ or javascript. Because Solidity is subject to continuous improvements, Pragma solidity is usually the first line of code within a Solidity file: it is a directive that specifies the compiler version to be used for current Solidity file.