What is a Smart Contract?

Ethereum is known as a “smart contract platform“.

platform (or computing platform) is an operating environment in which a piece of software, like programs or applications, can be run (or “executed”).

But what the heck is a smart contract?

What is a Smart Contract?

Smart contracts are automated computer programs that are hosted and executed on a blockchain. 

Smart Contract Code

Despite its name, “smart contracts” aren’t necessarily smart or legally binding.

Automated” instead of “smart” and “program” instead of “contract” would’ve been a better name, but I’m not the genius who came up with the concept!

Nick Szabo – who coined the term in the late 90’s – compared smart contracts to a vending machine.

Users insert coins into the machine and, assuming the inserted amount is correct, the machine “self-executes” and delivers the goods they requested. Nobody else was involved but you and the vending machine. No third-party involvement was required. Not even the vending machine owner.

The interaction requires little to no trust: the vending machine has no choice but to deliver the goods upon receiving the money.

Smart Contract Example

Now imagine writing agreements that have terms as clear and predictable as a vending machine and then using blockchain technology to automatically implement the terms of an agreement between parties.

That’s what a smart contract does.

In Ethereum, smart contracts are bits of coded instructions submitted onto the blockchain so that network participants can enforce and store these contracts in a secure and trustless manner.

In slightly more technical terms, a smart contract is a collection of code and data that resides at a specific address on Ethereum’s blockchain.

Smart contracts are also deterministic so that those involved in the contract know what results to expect when the contract is executed.

Think of a smart contract as a software program on the blockchain that automatically executes when predetermined conditions are met.

These predetermined conditions, directly written into lines of code, are the equivalent of the “terms of agreement” in a traditional contract.

Now that you know what smart contracts are, let me introduce you to what makes Ethereum a smart contract platform.

What is EVM?

EVM

No, it’s not a new type of electronic music.

If smart contracts are instructions written in code, it’s the Ethereum Virtual Machine (EVM) that executes them on the Ethereum blockchain.

A “virtual machine” is a piece of software that behaves like an actual physical computer that can run programs and deploy apps.

It’s basically a software program on a physical computer that works like it is a separate computer inside the main computer.

Why is a “separate computer” needed to execute smart contracts (which are just computer programs)?

Since not every Ethereum node (which are just computers) uses the same hardware, operating system (OS), and other settings, you need a way to “abstract” all this out so the code of the smart contract can just run without having to deal with all the different types of computer configurations with their specific requirements.

Otherwise, you’d have to write a different version of the smart contract for each type of computer configuration! 

Smart contracts don’t want to deal with all this drama!  It wants to be device-agnostic and OS-agnostic.

This is where the EVM comes in. 

It provides an execution environment for smart contracts, meaning a smart contract can execute (“run”) in any environment (“any computer or operating system”).

Developers can write a smart contract and be sure that it follows the software industry standard practice of “Write once, run anywhere” (WORA), also known as “Write once, run everywhere” (WORE).

Basically, a smart contract is will run on any computer with an EVM, Cool huh?

But that’s not the only cool thing.

Since the EVM’s purpose is to be the computation engine embedded in all full Ethereum nodes. it is Turing-complete. 

In computer-speak, “Turing-complete” means that EVM can theoretically compute anything you can think of computing.

So, in theory, ANY computer application can be programmed and run on the Ethereum platform!

Smart contracts are written in code using high-level programming languages like Solidity, Vyper, or Serpent.

This code gets compiled to something called “bytecode” by the EVM which then gets deployed to the Ethereum blockchain

Thanks to EVM, the Ethereum blockchain can go beyond smart contracts and can be used to create decentralized applications (dApps).