Ethereum for Developers
Overview of EVM, Ethereum standards, blocks, accounts, transactions, and improvement phases.
Note: Some changes are pending to this post after the Merge.
Ethereum is NOT a blockchain. It's NOT a cryptocurrency either! It's actually a protocol (a set of rules or procedures) like "HTTP" or "HTTPS".
Multiple independent blockchains run on the Ethereum protocol:
Ethereum Mainnet: This is the production network
Görli: This is a Proof of Authority testnet
Private networks: Development networks, and Consortium networks.
Layer 2 testnets: Arbitrum Rinkeby, and Optimistic Kovan.
When most people talk about Ethereum, they are talking about Mainnet - the primary public Ethereum production blockchain. This is where actual-value transactions occur on the blockchain. The native crypto of this Ethereum is Ether (ETH).
In this post, the terms Ethereum and Mainnet are used interchangeably.
Core Ethereum Mainnet metrics:
Block time: 12 to 14 seconds
Transactional Throughput: 14 tps
Transactional Finality: 6 mins
1. The Fork
Let's go back to 2016.
A bunch of really smart people came up with the concept of decentralized autonomous organizations (DAO). That's kind of like a cooperative society - think co-op banks or even the Amul milk co-op. The difference is that a DAO exists only on a blockchain and its rules are coded in "smart contracts".
So anyway, this DAO raised about $150 million USD worth of ether (ETH) through a token sale. But a really smart hacker exploited a bug in the "smart contract" and siphoned out all the money!
Now, logically nothing should have been done about this. Blockchains are "immutable" and "censorship-resistant", right?
But a bunch of people proved that Ethereum is neither "immutable" nor "censorship-resistant". They implemented a "hard fork" and rolled back Ethereum's history to before the hack.
This reallocated the hacked ether to a different "smart contract" and allowed investors to withdraw their funds.
The purists hated this and that's what led to Ethereum splitting into 2 blockchains:
This article is all about Ethereum (ETH).
2. Mindmap
Mindmap on Ethereum for Developers
3. Ethereum Virtual Machine (EVM)
One of the greatest blockchain innovations is the Ethereum Virtual Machine (EVM).
EVM is "the environment in which all 'Ethereum' accounts and smart contracts live". Smart contracts are programs that run automatically when some pre-defined conditions are met.
The sole purpose of the Ethereum protocol is to keep "the continuous, uninterrupted, and immutable operation" of the EVM. At any given block, Ethereum has only one "canonical" or unique state. EVM defines the rules for computing new valid states from one block to another.
EVM exists as a single entity maintained by a large number of connected computers (nodes) running an Ethereum client e.g. Geth or OpenEthereum. A client is a software that enables nodes to read blocks on the blockchain and smart contracts.
For details, see: https://ethereum.org/en/developers/docs/evm
4. Ethereum standards
The most popular Ethereum standards are:
ERC-20
This is a standard API for tokens within smart contracts. It provides basic functionality to transfer tokens and allow tokens to be approved and be spent by another on-chain third party.
For details, see: https://ethereum.org/en/developers/docs/standards/tokens/erc-20
ERC-721
This is a standard for non-fungible tokens (NFT). ERC-721 tokens are unique and can have a different value as compared to another token from the same smart contract - due to age, rarity, image, etc.
For details, see: https://ethereum.org/en/developers/docs/standards/tokens/erc-721
ERC-777
This is a fungible token standard that improves ERC-20.
For details, see: https://ethereum.org/en/developers/docs/standards/tokens/erc-777
ERC-1155
This is a multi-token standard. A single contract can include a combination of tokens - fungible, non-fungible, semi-fungible, etc. An ERC-1155 token can perform the functions of ERC-20 and ERC-721 tokens with more efficiency.
For details, see: https://ethereum.org/en/developers/docs/standards/tokens/erc-1155
ERC-4626
This is a standard API for tokenized yield-bearing vaults which represent shares of a single underlying ERC-20 token.
For details, see: https://ethereum.org/en/developers/docs/standards/tokens/erc-4626
Others
For a detailed list of Ethereum Token Standards, see: https://github.com/PhABC/ethereum-token-standards-list
5. Gas
Gas refers to the unit that measures the amount of computational effort required to execute specific operations on the Ethereum network.
Each Ethereum transaction requires a fee called "gas" because each transaction consumes computational resources. The gas fee is paid in ETH and denoted in gwei (0.000000001 ETH).
For details, see: https://ethereum.org/en/developers/docs/gas
6. Ethereum Blocks
A block is a bunch of transactions. Block time is the time it takes to mine a new block. The average Ethereum block time is 12 to 14 seconds.
A block contains the following fields:
slot: the slot the block belongs to
proposer_index: the ID of the validator proposing the block
parent_root: the hash of the preceding block
state_root: the root hash of the state object
body: an object containing several fields, as defined below
The block body contains several fields of its own:
randao_reveal: a value used to select the next block proposer
eth1_data: information about the deposit contract
graffiti: arbitrary data used to tag blocks
proposer_slashings: list of validators to be slashed
attester_slashings: list of validators to be slashed
attestations: list of attestations in favor of the current block
deposits: list of new deposits to the deposit contract
voluntary_exits: list of validators exiting the network
sync_aggregate: subset of validators used to serve light clients
execution_payload: transactions passed from the execution client
For details, see: https://ethereum.org/en/developers/docs/blocks
7. Ethereum Accounts
Ethereum has two account types:
Externally-owned: These are controlled by anyone with the private keys. They can be created for free & can initiate transactions. Transactions between externally-owned accounts can only be ETH or token transfers.
Contract: This is a smart contract deployed to the network. Creating them has a cost. They can only send transactions in response to receiving a transaction.
Both types of accounts can receive, hold and send ETH & tokens. They can interact with deployed smart contracts.
Ethereum accounts have 4 fields:
nonce
– A counter that indicates the number of transactions sent from the account.balance
– The number of wei owned by the address.codeHash
– This is the code of an account on the Ethereum virtual machine (EVM).storageRoot
– Also known as a storage hash.
For details, see: https://ethereum.org/en/developers/docs/accounts
8. Ethereum Transactions
An Ethereum transaction is an action initiated by an externally-owned account and not a contract e.g. sending ETH from one account to another.
A submitted transaction includes:
recipient
– the receiving address. If this is an externally-owned account, the transaction will transfer value. If this is a contract account, the transaction will execute the contract code.signature
– the identifier of the sender. It is generated by the sender's private key.value
– amount of ETH to transfer from sender to recipient.data
– optional field to include arbitrary datagasLimit
– the maximum amount of gas units that can be consumed by the transaction.maxPriorityFeePerGas
- the maximum amount of gas to be included as a tip to the miner.maxFeePerGas
- the maximum amount of gas willing to be paid for the transaction.
For details, see: https://ethereum.org/en/developers/docs/transactions
9. Ethereum improvement phases
The 5 proposed phases to improve Ethereum are:
Ethereum MERGE - this is the merging of the execution layer (Ethereum Mainnet) and the Beacon Chain (the new Proof-of-Stake layer). After this, ETH will become a deflationary asset and its power usage is expected to reduce by 99%.
Ethereum SURGE - this will bring sharding to Ethereum. Sharding will split the entire blockchain network into smaller partitions, called “shards”. This will increase the network's scalability to a great extent.
Ethereum VERGE - this will bring verkle trees which are a huge upgrade to Merkle trees as they enable much smaller proof sizes. This will optimize storage on Ethereum and help reduce the node size and make the blockchain more scalable.
Ethereum PURGE - this will eliminate historical data, reduce the hard drive space needed by validators, streamlines storage, and reduce network congestion.
Ethereum SPLURGE - these are a series of miscellaneous upgrades to ensure that the Ethereum network runs smoothly following the previous 4 stages.
Source: https://ethereum.org/en/upgrades/merge/
10. Ethereum Smart Contracts
A smart contract is a computer program, stored on a blockchain, that automatically executes when some pre-defined terms are met.
A smart contract:
is a type of Ethereum account
has a balance
can send transactions over the network
A smart contract is not controlled by a user. It is deployed to the network and runs as programmed.
User accounts can interact with a smart contract by submitting transactions which execute a pre-defined function.
Smart contracts can define rules and automatically enforce them via code.
By default, smart contracts cannot be deleted. Interactions with smart contracts are irreversible.
Smart contracts are like open APIs. This means you can call other smart contracts in your own smart contract to greatly extend what's possible. Contracts can even deploy other contracts.
You can write smart contracts using programming languages like:
Smart contracts need to be compiled before they can be deployed. Since deploying a smart contract is a "transaction", it requires the payment of gas.
Smart contracts cannot send HTTP requests. Hence we use oracles to get data on "real-world" events. Oracles act as middleware between smart contracts and external sources of data.
Chainlink is a decentralized network of independent oracle node operators. It provides:
price feeds of financial market data,
verifiable randomness that is needed for on-chain gaming,
proof of reserve for asset-backed cryptos such as stablecoins.
Chainlink is NOT a blockchain.
Each Chainlink oracle network comprises multiple independent oracle nodes. These nodes fetch data from multiple independent data providers. This data is then aggregated into a single data point and delivered "on-chain" for consumption by smart contracts. LINK is the crypto token that is used for paying Chainlink node operators for providing oracle services.
Multisig or multiple-signature smart contracts require multiple valid signatures to execute a transaction e.g. 3 of 5. Multisig prevents single points of failure.
OpenZeppelin provides a library of modular, reusable & secure smart contracts, written in Solidity.
11. Frameworks for building dApps
Building a decentralized application (dApp) is complex. That's why developers use dApp development software frameworks. Some of the functionalities of these frameworks are:
Spinning up local blockchain instances
Compiling & testing smart contracts
Connecting to Ethereum networks and deploying contracts - on local & public networks.
Integrating with storage solutions like IPFS
Truffle
Truffle is a popular Ethereum development framework with features like:
smart contract lifecycle management
automated contract testing
simple network management
Ganache
Ganache can be used to create a 1-click personal Ethereum blockchain for:
running tests,
executing commands, and
inspecting state
With Ganache, you can:
See the current status of all accounts - including their addresses, private keys, transactions & balances.
See the log output of the internal blockchain, including responses and other debugging information.
Configure advanced mining with custom block times.
Examine all blocks & transactions.
The Graph
The Graph is an indexing protocol for querying blockchain networks (like Ethereum) and IPFS.
12. Javascript API libraries
To enable dApps to interact with the blockchain, Ethereum clients implement the JSON-RPC specification with a uniform set of endpoints.
There are many Javascript API libraries that make it easy for developers to connect to and interact with Ethereum nodes.
Some of the functionalities are:
Querying the blockchain for block numbers, gas estimates, smart contract events, network id, etc.
Wallet functionality e.g. create wallets, manage keys, sign transactions, create accounts, send transactions, etc.
Interact with smart contract functions e.g. send a transaction to the smart contract & execute its method, estimate the gas a method execution will take when executed, deploy a contract, etc.
ethers.js
The ethers.js library has features such as:
Safely keeping private keys in the client.
Importing & exporting JSON wallets.
Importing & exporting BIP 39 mnemonic phrases.
Connecting to Ethereum nodes over JSON-RPC, INFURA, Etherscan, Alchemy, Cloudflare Ethereum Gateway, and MetaMask.
web3.js
web3.js is a collection of libraries enabling interaction with a local or remote ethereum node using HTTP, IPC or WebSocket.
Alchemy SDK
Alchemy SDK enables the building of:
NFT platforms and marketplaces.
DeFi solutions like DEXs, lending protocols, and liquidity aggregators.
web3 Wallets for accessing funds, collecting NFTs, and creating on-chain identities.
Decentralized Autonomous Organizations (DAOs).
13. Block explorers
Block explorers can be used to see real-time data on blocks, transactions, miners, accounts, and other on-chain activities. Some of the popular services include:
Thank you Rohas for the easy to comprehend write-up.
Will you be teaching Solidity coding in later classes?
Thanks
Great post detailing Ethereum fundamentals! Ethereum isn’t just a blockchain or cryptocurrency; it's a protocol enabling various blockchains. It includes Mainnet, testnets, and Layer 2 solutions. The EVM, smart contracts, and Ethereum standards like ERC-20 and ERC-721 are pivotal. For development, frameworks like Truffle and libraries like ethers.js are essential.https://devtechnosys.com/ethereum-development-company.php