Hello, fellow web developer! If you’re reading this, you’re probably interested in blockchains, smart contracts, etc., as someone who actually wants to write some smart-contract code. I’m going to walk you through setting up, writing, and deploying a smart contract to a real live Ethereum blockchain, and then interacting with that contract in a browser via a web service.
The Ethereum Virtual Machine
I’m not going to explain Blockchains 101 or Ethereum 101: there are many other places to go for that. But it’s probably worth discussing Ethereum at a very high level from a developer’s perspective.
You don’t need to care about mining or Proof-of-Work vs. Proof-of-Stake, or anything like that. But you should know that Ethereum is a decentralized virtual machine that runs on many nodes scattered around the world, and so-called “smart contracts” are code which runs (along with data which is stored) within that virtual machine, i.e. on every single node.
This is obviously hugely inefficient, but it has advantages; everyone in the world can rely on this code/data, because no central service or system can tamper with it; and anyone can submit code/data to this machine without the registering or asking permission. They do, however, need to pay. Every line of code and byte of storage in Ethereum has a price.
Ethereum, like Bitcoin, has a native currency, called “ether”; this is the same Ether currency that is traded on exchanges like Coinbase. When used to pay for Ethereum computing/storage, it is called “gas.” For any given smart contract, gas has a “limit” and a “price.” This is pretty confusing at first, but don’t worry, you’ll wrap your head around it eventually, and anyway this tutorial uses free fake money on a so-called “testnet” Ethereum blockchain.
In principle many languages can be compiled down to the bytecode used by the Ethereum VM, but in practice almost all smart contracts are written in the “Ethereum-native” language called Solidity. Solidity is still arguably somewhere between alpha-release and beta-release quality, and has lots of … idiosyncracies. (See this scathing commentary from six months ago: https://news.ycombinator.com/item?id=14691212 ) Still, it remains the de facto state of the art.
Most Solidity tutorials assume you’re running an Ethereum node on your machine, and/or one or more browser plugins. These steps add complexity & cognitive overhead and are not actually necessary. This tutorial is for web developers, who are accustomed to talking to APIs running on external servers; it will get your smart contracts up and running, on a real live blockchain, without ever needing to run an Ethereum node yourself.