Learn Ethereum, 2nd Edition [2 ed.]
9781804616512
Explore the Beacon chain, Ethereum's PoS consensus, and the upcoming merge of Eth1 and Eth2, along with the challen
130
23
57MB
English
Pages 1922
Year 2023
Report DMCA / Copyright
DOWNLOAD EPUB FILE
Table of contents :
Learn Ethereum
Contributors
About the authors
About the reviewer
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Share Your Thoughts
Download a free PDF copy of this book
Part 1: Blockchain and Ethereum Basics
1
Blockchain and Cryptocurrency
Technical requirements
Introducing blockchain technology
Decentralized P2P networks
How does blockchain work?
Rehashing cryptography
Public-key cryptography
Cryptographic hash function
Digital signatures
Anatomizing a blockchain consensus mechanism
What is consensus?
Proof-of-work
Proof-of-stake
Forking
Understanding Bitcoin and cryptocurrency
Bitcoin basics
What is a wallet?
Transactions, UTXO, and account balances
Genesis block and coin supply
How does Bitcoin payment work?
Limitations in Bitcoin
Altcoins
Overview of blockchain use cases in the industry and government
Financial services
Healthcare
Blockchain use cases led by government
Ushering in the world of Ethereum
Smart contract
EVM
Account
Summary
2
Ethereum Architecture and Ecosystem
Technical requirements
Introducing the Eth1 Architecture
Ethereum – the world computer
Web 2.0, Web3, to the Metaverse
DApps
Diving deep into Eth1
Accounts
Two types of accounts
EOAs
CAs
Transactions and messages
Smart contracts
Ether and gas
The EVM
Addresses and wallets
Examining mining in Eth 1.0
Mining and the consensus protocol
Ethereum transactions and block structure
Transaction validation and block verification
Understanding scaling challenges in Ethereum
The blockchain scalability trilemma
Modular blockchain architecture
Ethereum scaling solutions
Introducing Beacon Chains and Eth2
PoS in Eth2
How the beacon chain works
Benefits from the transition to PoS
Merging Eth1 and Eth2
Merging Eth1 data into Eth2
Scaling Ethereum with rollups
Optimistic rollups
ZK rollups
Summary
3
Decentralized Finance
Technical requirements
Introducing decentralized finance
Mastering Ethereum token standards
Definition of cryptocurrency
Crypto funding mechanism
Ethereum token standards
Analyzing stablecoins and MakerDAO Dai
Understanding DeFi protocols
Basic DeFi constructs
Lending and borrowing
Decentralized exchanges
Decentralized derivatives and insurance
Yield farming and DeFi continuum
Making sense of cryptoeconomics
DeFi after the collapse of FTX
Summary
4
EVM-Compatible Blockchain Networks
Technical requirements
Understanding EVM blockchain ecosystems
Introducing BSC
Consensus mechanism in BSC
Block creation and finality
BNB governance
BNB ecosystem and roadmap
Scaling Ethereum with Polygon chains
How Polygon PoS and Plasma work
Block production and checkpoints
Consensus mechanism in Polygon PoS
Multi-chain solutions with Polygon Edge
Polygon ecosystem and roadmap
Diving deep into high-performance Avalanche chains
Avalanche blockchain architecture overview
Avalanche consensus mechanism
Subnets and enterprise blockchains
Governance in Avalanche chains
Avalanche ecosystem
Bridging interoperability gaps between blockchains
Cross-chain integration challenges
Common cross-chain bridge designs
Trustless bridge solutions using Polkadot
Generalized bridge solutions with Cosmos
Decentralized oracle as a bridge
Glancing over non-EVM blockchain networks
TRON blockchain overview
Introduction to Solana
Summary
5
Deep Research and the Latest Developments in Ethereum
Technical requirements
Understanding the challenges in distributed systems
The CAP theorem
Horizontal scaling versus vertical scaling
Scaling Ethereum
Making sense of the Ethereum roadmap
Pivotal to rollup-centric
Overview of the post-merge Ethereum roadmap
Sharding and data availability sampling
Data availability sampling
Discovering MEV and PBS
Overview of MEV
MEV implementation in Ethereum
Proposer builder separation
zkEVM and EVM improvements
Overview of zk-SNARK
Types of zkEVM implementations
Workings of zkEVM
Smart contract wallets and account abstraction
Account abstraction and EIP 4337
How a smart contract wallet works
DAOs
Introduction to DAOs
DAO governance case study using Uniswap
NFTs, Web3, and Metaverse
Introduction to a world of NFTs, Web3, and Metaverse
The current state of NFTs
Web3 and the future of the internet
The Metaverse, virtual reality, and future interactions
Summary
Part 2:Ethereum Development Fundamentals
6
Fundamentals of Solidity
Technical requirements
Introducing Solidity
Tools for the Solidity development environment
Learning about the fundamental programming structure in Solidity
The layout of a Solidity source file
State variables
Built-in data types
User-defined data types
Functions
The pure, view, and payable functions
Constructor and destructor functions
Fallback function
Function overloading
Function modifiers
Events
Global variables, contextual variables, and functions
Enabling the contracts library
Understanding inheritance, abstract contracts, and interfaces
Interface
Abstract contract
Inheritance
Multiple inheritance and the diamond problem
Function overriding
Examining smart contract execution under the hood
Mastering advanced programming concepts in Solidity
Smart contract security
Keeping contracts simple and modular
Use the checks-effects-interactions pattern
DoS with block gas limit
Handling errors in external calls
Best practices in smart contracts
Writing upgradable smart contracts
Economic consideration of smart contract execution
Types of smart contract
Putting it all together – rental property leasing
Summary
7
Web3 API Fundamentals
Technical requirements
Introducing Web 3.0
Setting up an Ethereum environment
Installing Geth
Setting up a private Ethereum network
Generating and configuring the genesis file
Initializing the chain instance
Starting a Geth node
Connecting to Ethereum networks
Learning the fundamentals of web3.js – the Ethereum JavaScript API
web3.js project setup
web3.js Account
web3.js ABI
Web3 providers
Setting up the Ethereum testnet environment
The web3.js Transaction API
Getting started with web3.py
Prerequisites
Introducing Web3j – Web3 Java Ethereum DApp API
Setting up a simple Spring Boot application
Checking the balances of Ethereum accounts
solc and the Web3j CLI
Deploying smart contracts using Web3j
Transacting with a smart contract
Querying the state of a smart contract
Summary
8
Developing Your Own Cryptocurrency
Technical requirements
Understanding token standards
ERC-1155
Batch transfers
Batch balance
Batch approval
ERC-1155’s TokenReceiver
Setting up an Ethereum development environment
Working with Truffle
Creating an ERC-20 token – MyERC20Token
Creating basic token information
Defining and implementing the ERC-20 interface
Assigning an admin role
Working with the whitelist function
Locking and unlocking an account
The mint and burn tokens
Creating an ERC-721 token – DigitalArtERC721Token
Designing the decentralized digital art marketplace
Setting up the DigitalArtERC721Token project
Creating the basic token information
Defining and implementing the ERC-721 standard
Defining the art and art transaction struct
Creating a non-fungible digital art token
Implementing the buyArt() function
Implementing the resellArt() function
Implementing the findArt() function
Implementing the findMyArts() function
Implementing the findAllPendingArt() function
Getting all art transactions through getArtAllTxn()
Creating an ERC-1155 token – ERC1155NFTToken
Uploading NFT images
Writing the ERC-1155 NFT token contract
ERC-1155
Summary
Part 3: Ethereum Development Fundamentals
9
Smart Contract Development and Test Fundamentals
Technical requirements
Understanding Remix development fundamentals
Working with the Solidity Compiler
Testing
Deploying and running transactions
Debugging
Understanding development using Truffle and unit testing
The Truffle console and development features
Running a Truffle migration
Truffle unit testing
Truffle Box
Understanding Hardhat development and unit testing
Hardhat Runner
Hardhat Network
Project structure
Installation and environment setup
Hardhat project setup
Creating and compiling the ERC1155 contract
Testing the contract
Deploying the contract
Security testing
Static and dynamic analysis
Working with a linter
Summary
10
Writing a Frontend to Build the NFT Marketplace DApp
Technical requirements
Understanding DApps
Creating your first NFT
Set up a wallet
Obtain Ether (ETH)
Visit OpenSea
Create NFT item
Working with the Web3 JavaScript API
Setting up a DApp development environment
Installing Ganache desktop
Creating a development workspace
Setting up the project for our DApp
Deploying a smart contract
Installing MetaMask and connecting to Ganache
Setting MetaMask Ganache accounts
Building frontend UI components
Setting up project dependencies
Getting the instance of a deployed contract
Building a navigation bar
Running the digital art market DApp
Publishing your art (the first account)
Publishing your art (the second account)
Summary
11
Ethereum Tools and Frameworks
Technical requirements
Understanding the Ethereum development tools and framework
Layer 1 node connections
Working with Infura
Working with the Infura Ethereum API
Using Remix with Infura
Introducing Alchemy
Testing tools
The Ethereum client API
Working with Ethereum storage
Working with Swarm
Getting to know the popular smart contract libraries
Working with OpenZeppelin
Setting up a dev environment
Access control
Programming languages and integrated development environments
Vyper
Summary
Part 4:Production and Deployment
12
Setting Up Ethereum Private Chain
Technical requirements
Understanding private Ethereum networks
Setting up a local private network
Prerequisites
Installation on MacOS with Homebrew
Creating a private Ethash network using Besu
Private enterprise Ethereum in production use
Hyperledger
Hyperledger Fabric
Hyperledger Sawtooth
Corda
Quorum
Resources for private enterprise Ethereum development
Ethereum node services
Ethereum clients
Summary
13
Deployment of Your DApps
A brief introduction to test networks
Deploying a smart contract to a test network using Truffle
Installing Truffle
Deploying a smart contract to the Goerli testnet using Truffle
Deploying a smart contract to the Sepolia testnet
Deploying a smart contract to a test network using Hardhat
Installing Hardhat
Deploying a smart contract to the Goerli testnet using Hardhat
Summary
14
Building Ethereum Wallets
Technical requirements
Understanding the wallet technology
Understanding non-deterministic and deterministic wallets
Mnemonic code words (BIP-39)
Generating a private key in Ethereum
Multiparty signature wallets
Stealth addresses
Basic stealth address protocol
ISAP
Dual-Key stealth address protocol
Confidential transactions
Creating an Ethereum wallet
Creating a non-deterministic wallet
Viewing the Keystore file generated by the geth command
Creating a non-deterministic wallet with MyCrypto
Creating an HD wallet
Working with third-party Ethereum wallets
Wallets on different platforms
Smart contract wallets
Hot and cold wallets
Transferring funds between wallets
Summary
15
Oracles, Technology, and Layer 2 in Practice
Technical requirements
Understanding oracles
Examples of blockchain oracles
Event data for prediction markets
Blockchain network
Types of oracles
Working with oracles
Introduction to Chainlink
Chainlink VRF DiceRollGame
Diving deep into cross-chain technology
How does a cross-chain bridge work?
Vulnerabilities in a cross-chain bridge
Popular cross-chain bridges
Cross-chain in practice
Bridge tokens from Ethereum to Avalanche
Bridging ETH from Ethereum to Polygon (MATIC)
Working with Layer 2
Optimistic rollups
ZK rollups
Writing a ZKP program using ZoKrates
Summary
Part 5:Conclusion
16
Conclusion
Technical requirements
Facing the challenges of Ethereum and blockchain
Scalability and economic security
User experience, privacy, and mainstream adoption
Ethereum governance
CBDC and government regulations
Emerging trends in Ethereum and the blockchain ecosystem
Application blockchain
Enterprise blockchain and blockchain as a service
The multi-chain world
AML/CFT, KYC, and decentralized identity
Blockchain-powered Metaverse
Meeting the future of Ethereum
Summary
Index
Why subscribe?
Other Books You May Enjoy
Packt is searching for authors like you
Share Your Thoughts
Download a free PDF copy of this book