-
Ethereum: An open source, programmable public blockchain platform.
-
Ethereum Virtual Machine (EVM): Capable of executing logic, algorithms, and process data inputs.
-
Turing Complete: Any software that is able to run code written by a developer or executed by an end user.
-
Smart Contract: A contract written in code. More specifically, it is an object on the Ethereum blockchain that contains EVM code functions.
These smart contracts will exist and be executable so long as the network exists. Just like other blockchain technologies, there is no one that owns this contract and no one can take it down, not even you. A smart contract will only disappear if it’s programmed to self-destruct with a kill switch. For this reason, having a kill switch is a good practice when working with smart contracts.
-
Solidity: High level language for coding and deploying smart contracts.
- Frontier: First release of the Ethereum network. This release enabled developers to experiment, mine ETH, and start building decentralized applications.
- Homestead: Second release of the Ethereum network. This came with many protocol improvements, and became a foundation layer for many more upgrades that followed.
- Metropolis: Third release of the Ethereum network. The plan was to provide a lighter, faster and more secure client and network.
- Serenity: Fourth release of the Ethereum network. In this release the long-awaited transaction to Proof of Stake (POS) consensus algorithm is expected.
Instead solving a puzzle, the validators have to stake or deposit ether. This is the algorithm used by Ethereum after Ethereum updated to Casper. A Proof of Stake consensus algorithm depends on a validator’s economic stake in the network. In the case of Ethereum, it is the amount of ether that is owned by a user.
PoS Types
-
Chain-based Proof of Stake : The validators are pseudo randomly chosen every so often at a predetermined time slot. They are tasked to create a block that points to some previous block. In most cases, the previous block is the single longest growing chain.
-
Byzantium fault-tolerance based Proof of Stake: The validators are also randomly chosen and tasked to just propose a block. The process of agreeing on a block is done by validators sending a vote. One of the key distinctions here, is that the consensus can occur within one block, and it’s not dependent on the length or size of the chain.
PoS Benefit
-
- Copious amount of electricity is not required. Estimates lead us to believe that one million dollars worth of electricity plus hardware costs are spent every day to keep the Proof of Work consensus algorithm running. By switching to Proof of Stake, we can expect direct savings here.
-
- Issuance of several new coins might not be necessary. Reduction in high electricity consumption, will potentially reduce the need to issue as many new coins, so as to keep the miners and validators motivated to continue to participate and secure the network.
-
- Potentially discourages selfish miners. One issue is that miners vote for changes to the protocol which governs them. This makes it so, that miners can potentially be selfish in deciding what is best for themselves, versus what is the best for the protocol. Using a range of Game Theory mechanisms, Ethereum is working on implementing techniques that will eventually discourage centralized mining grids, to act in a selfish manner.
-
- Rewards are not exponential to Economies of Scale. Centralized miners benefit from the Proof of Work and the economies os scale. i.e. if they had 10 million, the returns would be 10 times higher than one million, as they can afford to secure a vast majority of better hardware.
-
- Less chances for a 51% attack because of economic penalties. One major issue with Proof of Work, is the possibility of a 51% attack. That’s when the majority of the network power used for mining is owned by a single malicious entity. Once they have control, they are able to take over the network and ruin the validity of the blocks in the chain. In Proof of Stake, this isn’t possible. That’s because, if anyone were to have a majority stake in the protocol, they would still be incentivized to have the best interests of the chain in mind. Plus the economic penalties are expensive in Proof of Stake. So, theoretically, this should encourage good actors and discourage bad actors.
Account Types
-
Externally owned accounts (EOA’s): Individuals holding a private key manage externally owned accounts. Contents:
- Account balance
- Transaction Count Abilities:
- Send transactions
- Initiate a smart contract
- Transfer value from its wallet.
-
Contract Account (CA’s): They are accounts controlled by the code within a smart contract. Contents:
- Account balance
- Transaction Count
- Smart contract code Abilities:
- Transfer value
- Initiate another smart contract
- Execute smart contracts
- Manipulate storage
Account State Variables
- Nonce: Number of transactions on the account. In a CA, it’s the number of contracts created by the account.
- Account Balance: Total value of Ether available on the account in Wei.
- Storage Hash: Root node of the patricia tree.
- Code Hash: Hash of the code within the smart contract. This hush cannot be changed. This is the reason that smart contract code cannot change after it’s deployed. In EOA’s. there’s no code, so the code hash is empty.
Nonce Transaction count from the sender’s account.
Gas Price Price per unit of gas you are willing to pay for executing the code in your smart contract.
Gas Limit Specifies the max number of computational steps the transaction is allowed.
To Recipient’s address
Value The amount of Ether you want to send.
Data, Init Information used to record the creation and execution of smart contracts.
When sending Ethereum transactions, you’re asking the network to execute code that sends ether to another account. Nodes execute this code in the network. Miners get paid fees using what’s known as gas.
In ethereal, gas accounts for the total cost of executing operations on the contract. Once completed, Ethereum converts this gas into its value in ether and this either goes to the node that executed the transaction.
A low Gas Price will be cheap but it’s less likely that a miner would pick up this work. A high gas price is more likely to get picked up but can get very expensive if you want to execute this code many times. Finding a gas price that is both affordable and effective is a balance you’ll need to consider when determining the gas price. It’s not an exact relationship like shown here, but hopefully this graph helps get the point across.
Setting Gas Limit is important for a few reasons. One, it allows you to work within a budget that you’re comfortable with. It also safeguards you from potential errors in the contact.
The Ethereum Virtual Machine (EVM) is responsible for an enormous amount of tasks. Given it's worldwide set of computer nodes that contribute to the creation of this EVM, it also goes by the name of "The World Computer".
EVM (technical definition) A virtual machine that executes code. A runtime environment for Smart Contracts.
Once a smart contract is written, it’s compiled into two views. A byte code view that is machine-readable, and an assembly view, which is human-readable. Then this compiled code executes on the EVM, which executes the logic of your program.
Terms and Definitions Throughout this video, PK mentions many terms related to Ethereum network performance. For future reference, here is a list of each of these terms along with the definitions provided in the video.
BestBlock: The highest block number of the longest valid chain, said differently it is heavy with cumulative difficulty.
Uncles: Orphaned blocks and unlike other blockchains, in Ethereum they are included and rewarded. The dashboard displays current bloc uncle count and that from last 50 blocks.
LastBlock: The time since the last mined block in seconds.
AverageBlock: Average time between two block (excl. uncles) - should display 15 seconds unless the network is really slow.
AverageNetworkHashrate: Number of hashes spent by miners to find a new block. 250 TH/s is 250 trillion network hash power per second.
Difficulty: Also known as the mining difficulty to find a new block.
ActiveNodes: The number of nodes connected to the dashboard. The total number of active connected nodes powering the network is quite high.
GasPrice: The price miners are currently accepting. Currently it is ~40 gwei, which is 40 giga wei, which is 40 billion wei. The default is 20 gwei.
GasLimit: The gas limit for a block. The dashboard reads 7,999,992 gas and the miner can include transactions until the block is full and limit is met. The default is 4,712,388 (1.5 pi million gas) In bitcoin you might have come across block size limit.
PageLatency: A dashboard stat.
Uptime: A dashboard stat.
BlockTimeChart: Maps out actual time between blocks.
DifficultyChart: Maps out actual difficulty of previous blocks.
BlockPropagationChart: For the nodes connected to the dashboard, it is how fast blocks are shared/propagated between nodes.
LastBlockMiners: Displays the public key of the last miners who found the most number of blocks.
UncleCountChart: Displays number of uncles per 25 blocks per bar.
TransactionsChart: Displays the number of transactions included in previous blocks.
GasSpendingChart: Correlated to Transactions Chart and displays the amount of spent gas.
GasLimitChart: Dynamic in nature and shows Gas Limit for the previous blocks.
Goals
-
Create a random private key (of 64 hexadecimal characters | 256 bits | 32 bytes)
-
Derive a public key from the above private key (of 128 hexadecimal characters | 512 bits | 64 bytes)
-
Derive an address from the above derived public key (of 40 hexadecimal characters | 160 bits |20 bytes)
Commands Here is a list of the commands shown throughout the video that you can run on your computer.
Generate Private Key
openssl ecparam -name secp256k1 -genkey -noout
Example Output
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIOVtf2mBMYtygiqAoMLk1weZj2uXmGCagGxALeZnHQWoAcGBSuBBAAKoUQDQgAEBKrAcZsycPPgJf+uzTF+xZ35v8og4+P7fvHJ81jCXpNyfyfrg8e1goNYamwfd8MEgS3u/qJOSSEsoc+saTDVg==
-----END EC PRIVATE KEY-----
Generate a random Private Key & Derive a Public Key
openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout > Key
Display Key File
cat Key
Example Output
Private-Key: (256 bit)
priv:
00:a8:a6:02:44:37:16:3f:1b:20:1d:61:8c:45:5c:
33:88:09:97:0c:38:59:19:c9:82:1c:10:9d:30:36:
29:e8:53
pub:
04:17:2d:96:31:e3:18:46:9a:80:6c:7f:b5:a3:d1:
27:d8:3f:ac:ca:f9:f5:18:69:65:c7:82:dc:b0:4b:
51:1e:56:7a:67:f9:33:4a:a3:72:fc:3b:55:78:d2:
2d:1a:3f:30:5b:bd:38:69:66:14:41:16:8d:b7:12:
34:19:2c:4f:88
ASN1 OID: secp256k1
Extract the Private Key, remove leading zero, and save to a file 'priv'
cat Key | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//' > priv
cat priv
Example Output
3-00a8a6024437163f1b201d618c455c4-338809970c385919c9821c109d30365-29e853
Extract the Public Key, remove EC prefix 0x04, and save to a file 'pub'
cat Key | grep pub -A 5 | tail -n +2 |tr -d '\n[:space:]:' | sed 's/^04//' > pub
Example Output
7-04172d9631e318469a806c7fb5a3d18-27d83faccaf9f5186965c782dcb04b9-511e567a67f9334aa372fc3b5578d210-2d1a3f305bbd3869661441168db71211-34192c4f88
Generate the hash, and save to a file 'address'
cat pub | keccak-256sum -x -l | tr -d ' -' | tail -c 41 > address
cat address
Example Output
a95fdeec5607856dd71b3c466af62a6e895a8a6aa
Key Outputs
1.3-00a8a6024437163f1b201d618c455c4-338809970c385919c9821c109d30365-29e853
2.7-04172d9631e318469a806c7fb5a3d18-27d83faccaf9f5186965c782dcb04b9-511e567a67f9334aa372fc3b5578d210-2d1a3f305bbd3869661441168db71211-34192c4f88
3.a95fdeec5607856dd71b3c466af62a6e895a8a6aa
What is Geth? Geth is a multipurpose command line tool that runs a full Ethereum node implemented in the programming language Go. It has three interfaces - an interactive console, the command line subcommands and options, and a json-rpc server.
Commands Install Geth
$ brew tap ethereum/ethereum
$ brew install ethereum
or brew upgrade ethereum
Sync to the Rinkeby Test Network
$ geth --rinkeby --syncmode "fast"