# My Web3 Transition Journey at Blockfuse Labs --- ### Week 2: Deep Dive into Ethereum Key Concepts The second week, we discussed the following topics: - Ether Currency Units - Types of Accounts (EOAs & SCAs) - Ethereum Clients - Ethereum Networks - Ethereum Nodes - Cryptography, Keys & Addresses - Public Key & Private Key - Elliptic Curve Cryptography - Generating Public Key - Wallets (Deterministic & Non-Deterministic Wallets) - Seeds and Mnemonic Codes (BIP-39) - How Mnemonic Words Are Generated - How Seed Phrases Are Derived from Mnemonic Words (PBKDF2) - Transactions & Components of a Transaction - Digital Signature So, let's dive in! ## Ether Currency Units Let's start with the very foundation of transactions on the Ethereum network (Ether). Ether (ETH) is the native cryptocurrency of Ethereum, and just like dollars have cents and naira have kobo, Ether is divided into smaller units. Here's how it breaks down: - **Wei**: This is the smallest unit of Ether. 1 Ether equals a whopping 10^18 Wei! Imagine trying to buy a cup of coffee with that many Wei, sounds crazy, right? 😂 - **Kilowei (Babbage)** - **Megawei (Lovelace)** - **Gwei**: A more commonly used unit, especially when talking about gas fees. 1 Gwei is equal to 10^9 Wei. So, when you're adjusting gas prices, you're likely dealing with Gwei. - **Microether (Szabo)** - **Milliether (Finney)** - **Ether**: Finally, we have the base unit, Ether itself. This is what you'll see most often when sending and receiving transactions. - **Kiloether (Grand)** - **Megaether** Understanding these units is crucial, especially when you're dealing with smart contracts and need to specify precise amounts. ## Types of Ethereum Accounts Next, let's talk about the two types of accounts that exist on the Ethereum network: Externally Owned Accounts (EOAs) and Smart Contract Accounts (SCAs). - **Externally Owned Accounts (EOAs)**: These are the accounts that you and I might control. EOAs are managed by private keys, which means you hold the power to send transactions and manage Ether. Think of EOAs as your personal bank account in the Ethereum world. Every time you want to transfer Ether or interact with a smart contract, your EOA is the one signing off on the transaction. - **Smart Contract Accounts (SCAs)**: Unlike EOAs, SCAs are not controlled by individuals, they are controlled by code. These accounts belong to smart contracts, which are self-executing programs on the blockchain. SCAs can hold and transfer Ether, but they operate based on predefined rules encoded in their contract. This makes SCAs incredibly powerful, as they can automatically execute tasks without needing any human intervention. ## Ethereum Clients To interact with the Ethereum blockchain, we need something called an Ethereum client. Think of an Ethereum client as software that allows your computer to communicate with the Ethereum network. Some of the most popular clients include: - **Geth (Go Ethereum)**: The most widely used client, written in Go. It's great for running your own node and participating in the network. - **Parity (now OpenEthereum)**: Known for its speed and efficiency, Parity is another popular client that's often used in enterprise settings. It is written in Rust. - **Besu**: A Java-based client designed with enterprise use in mind, particularly for permissioned networks. These clients are the backbone of the Ethereum ecosystem, enabling nodes to sync with the network, validate transactions, and participate in consensus. ## Ethereum Networks Ethereum isn't just one network, it's a collection of different networks designed for various purposes. Let's break it down: - **Mainnet**: This is the primary Ethereum network where real-world transactions happen. When you hear about people trading Ether or deploying smart contracts, it's almost always on the Mainnet. - **Testnets**: These are networks like Ropsten, Rinkeby, and Goerli, which are used for testing. Developers use testnets to deploy and test their smart contracts before going live on the Mainnet. The beauty of testnets is that you can experiment without risking real Ether. ## Ethereum Nodes Now, you might be wondering, what exactly is an Ethereum node? Simply put, a node is a computer that's running an Ethereum client. Nodes are the lifeblood of the Ethereum network, they store a copy of the blockchain, validate transactions, and help maintain the network's security and integrity. There are different types of nodes, including full nodes, light nodes, and archive nodes, each serving a specific role in the ecosystem. - **Full Node**: Stores the entire Ethereum blockchain, including all transactions, smart contracts, and state data. Full nodes validate transactions and blocks and provide data to light clients. - **Light Node (or Light Client)**: Stores only the block headers and requests data from full nodes as needed. Light nodes are useful for devices with limited storage or bandwidth. - **Archive Node**: A full node that also stores historical data, such as past transactions and state data. ## Cryptography & Keys Cryptography means "secret writing" in Greek. At the heart of Ethereum's security lies cryptography. Cryptography is the art of secure communication, and in the context of Ethereum, it plays a crucial role in ensuring that transactions are secure and that only the rightful owner of an account can control it. - **Public Key (Asymmetric Cryptography)**: This is derived from your private key and is used to generate your Ethereum address. It's kind of like your public ID on the blockchain, people can send Ether to your public address, but they can't access your funds. - **Private Key**: A private key is simply a number, picked at random. Ownership and control of the private key is the root of user control over all funds associated with the corresponding Ethereum address, as well as access to contracts that authorize that address. This is your secret key, never share it with anyone! Your private key allows you to sign transactions, proving that they are coming from you. - **Elliptic Curve Cryptography (ECC)**: This is the cryptographic method used to generate your public and private keys. ECC is chosen for its strong security and efficiency, making it ideal for blockchain applications. ## Generating Public Key When you create an Ethereum account, your private key is generated first. Then, through a process called elliptic curve multiplication, your public key is derived from this private key. This public key is then hashed to produce your Ethereum address. The entire process is designed to be secure and irreversible - meaning that, while it's easy to generate a public key from a private key, it's practically impossible to reverse the process. Starting with a private key in the form of a randomly generated number `k`, we multiply it by a predetermined point on the curve called the generator point `G` to produce another point somewhere else on the curve, which is the corresponding public key `K`: *`K = k * G`* ## Elliptic Curve Multiplication Elliptic curve multiplication is a fundamental concept in cryptography and is specifically crucial in Ethereum for generating public keys from private keys. It is a mathematical operation used in Elliptic Curve Cryptography (ECC) and is a key component of cryptographic algorithms like ECDSA (Elliptic Curve Digital Signature Algorithm). ### Elliptic Curve Multiplication Process Elliptic curve multiplication is the process used to generate a public key from a private key in ECC. Here's how it works: - **Private Key (k)**: This is a randomly chosen large integer. It acts as a scalar in the multiplication process. - **Generator Point (G)**: This is a predefined point on the elliptic curve, known to everyone. It is a constant and part of the curve's domain parameters. - **Public Key (K)**: This is the point on the elliptic curve obtained by multiplying the private key `k` with the generator point `G`. The multiplication is not regular arithmetic but involves repeated addition of the point `G` on the curve. Mathematically, this can be written as: *`K = k * G`* Where: - `K` is the public key. - `k` is the private key. - `G` is the generator point. ## Wallets Now let's talk about wallets,these are essential tools in the Ethereum world. There are two main types of wallets: - **Deterministic Wallets**: These wallets generate all of their keys from a single seed. This means that if you back up your seed phrase (which we'll talk about in a moment), you can recover all of your keys. This is incredibly convenient, as it means you only need to remember or securely store one piece of information. - **Non-Deterministic Wallets**: These generate keys randomly and independently of one another. While this might sound more secure, it also means that if you lose a key, there's no way to recover it unless you've backed up each one individually. ## Seeds and Mnemonic Codes (BIP-39) Speaking of backups, let's dive into seeds and mnemonic codes, specifically BIP-39. BIP-39 stands for Bitcoin Improvement Proposal 39, but it's widely used across various blockchain networks, including Ethereum. It's a standard that defines how mnemonic phrases (those 12 or 24 words you might be familiar with) are created. - **Mnemonic Codes**: These are human-readable phrases generated from a seed, making it easier to back up and restore your wallet. Instead of writing down a long, complicated string of characters, you get a series of words that are much easier to remember and store securely. - **Seeds**: The seed is the master key to your wallet. From this single seed, all of your private and public keys are derived. If you have your seed, you can recover all of your accounts, keys, and funds. ## How Mnemonic Words Are Generated Mnemonic words are generated from a seed using a specific algorithm. Here's how it generally works: 1. **Generate Entropy**: The first step is to generate a random number called entropy. The size of the entropy can vary, but common sizes are 128, 160, 192, 224, or 256 bits. 2. **Create a Checksum**: A checksum is added to the entropy to help detect errors. The checksum is a small piece of data derived from the entropy itself. 3. **Combine Entropy and Checksum**: The entropy and checksum are combined to form a binary string. 4. **Divide into Groups**: This binary string is then divided into 11-bit groups. 5. **Map to Word List**: Each 11-bit group is then mapped to a word from a predefined word list. This word list is standardized and contains 2048 words. The result is your mnemonic phrase. ## How Seed Phrases Are Derived from Mnemonic Words (PBKDF2) Once you have your mnemonic phrase, it's converted into a seed using the PBKDF2 (Password-Based Key Derivation Function 2) algorithm. This seed can then be used to generate all of your private keys. Here's a simplified version of how PBKDF2 works: 1. **Input**: The mnemonic phrase and a salt (often a user-provided passphrase) are input into the algorithm. 2. **Hashing**: The algorithm applies a cryptographic hash function (usually SHA-512) multiple times to produce the final seed. The number of iterations can be specified to increase security. 3. **Output**: The result is a 512-bit seed, which can be used to generate all of your wallet's keys. ## Transactions & Components of a Transaction Ethereum transactions are the lifeblood of the network. Every action, from transferring Ether to interacting with a smart contract, involves a transaction. Let's break down the components: - **Nonce**: A unique number that ensures each transaction can only be processed once. Think of it as a transaction counter for your account. - **Gas Price**: The amount you're willing to pay per unit of gas to get your transaction processed. Gas prices are usually specified in Gwei. - **Gas Limit**: The maximum amount of gas you're willing to use for the transaction. Complex operations like smart contracts require more gas. - **Recipient**: The address of the account you're sending Ether or data to. - **Value**: The amount of Ether you're sending. - **Data**: Optional data payload that can be included with the transaction. This is often used when interacting with smart contracts. - **V, R, S**: These are the components of the transaction's digital signature, which prove that it was signed by the account holder. ## Digital Signature When you initiate a transaction, you sign it with your private key. This digital signature is a mathematical scheme that allows the network to verify that the transaction was indeed sent by you, without revealing your private key. The signature consists of three components - V, R, and S, which are included in the transaction and allow the network to verify its authenticity. --- We will continue our journey and explore more advanced topics like smart contracts, Ethereum Virtual Machine (EVM), and how to deploy your first smart contract.