Share E-Book

AuthorAndreas M. Antonopoulos, Gavin Wood, Carlo Parisi, Alessandro Mazza, Niccolò Pozzolini

As the first blockchain platform to introduce the concept of smart contracts, Ethereum is the gateway to a worldwide decentralized computing paradigm. With this practical guide, the authors provide everything you need to know to start building smart contracts and DApps on Ethereum and other virtual machine blockchains. Through comprehensive coverage of Ethereum's internal workings, you'll understand not just the how but also the why of Ethereum's innovative technology. And practical deep dives into the architecture and operational mechanics will equip you with the knowledge and tools to explore further developments in Ethereum and the wider blockchain world. Run an Ethereum client, create and transmit basic transactions, and program smart contracts Learn the essentials of public key cryptography, hashes, and digital signatures Understand how "wallets" hold digital keys that control funds and smart contracts Learn security best practices, design patterns, and antipatterns with real-world examples Learn the essentials about DeFi and zero knowledge proofs Understand how the Consensus of Ethereum works and the challenges it presents Read and write basic Solidity and Vyper code

AI Reading Assistant

Summary and highlights from this book's index; jump to passages in the text

Passage locations
Tags
No tags
ISBN: 1098168429
Publisher: O'Reilly Media
Publish Year: 2025
Language: 英文
Pages: 571
File Format: PDF
File Size: 16.8 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Andreas M. Antonopoulos, Gavin Wood, Carlo Parisi, Alessandro Mazza & Niccolò Pozzolini Mastering Ethereum Implementing Smart Contracts 2nd Edition
ISBN: 978-1-098-16842-1 US $69.99 CAN $87.99 DATA As the first blockchain platform to introduce the concept of smart contracts, Ethereum is the gateway to a worldwide decentralized computing paradigm. With this practical guide, the authors provide everything you need to know to start building smart contracts and DApps on Ethereum and other virtual machine blockchains. Through comprehensive coverage of Ethereum’s internal workings, you’ll understand not just the how but also the why of Ethereum’s innovative technology. And practical deep dives into the architecture and operational mechanics will equip you with the knowledge and tools to explore further developments in Ethereum and the wider blockchain world. • Run an Ethereum client, create and transmit basic transactions, and program smart contracts • Learn the essentials of public key cryptography, hashes, and digital signatures • Understand how “wallets” hold digital keys that control funds and smart contracts • Learn security best practices, design patterns, and antipatterns with real-world examples • Learn the essentials about DeFi and zero knowledge proofs • Understand how the Consensus of Ethereum works and the challenges it presents • Read and write basic Solidity and Vyper code Andreas M. Antonopoulos is a critically acclaimed bestselling author, speaker, and educator, and one of the world’s foremost Bitcoin and open blockchain experts. Gavin Wood is a blockchain pioneer with a master’s and doctorate in computer science. He coded the first functional Ethereum implementation, created the Solidity contract language, and authored the “Ethereum Yellow Paper.” Carlo Parisi, also known as Blackie, is a senior Solidity smart contract developer, senior auditor, and content creator with a degree in computer science. Alessandro Mazza is a Web3 developer with a degree in software engineering. He has contributed to the Ethereum core protocol, specializing in the execution layer. Niccolò Pozzolini is a senior smart contract auditor and developer who specializes in blockchain security and has a master’s degree in software engineering. Mastering Ethereum “I’ve taught crypto devs for many years. If you want to go from zero to hero in smart contracts, Mastering Ethereum is the definitive no-fluff guide I recommend above all to achieve that.” Gonçalo Magalhães, head of security, Immunefi
Praise for Mastering Ethereum, 2nd edition “Ethereum has evolved, and now so has Mastering Ethereum. With updates on the fundamentals, best practices, and practical examples, the second edition will be rewarding for both experts and new learners.” —Andreas M. Antonopoulos, author of Mastering Ethereum, 1st edition “I’ve taught crypto devs for many years. If you want to go from zero to hero in smart contracts, Mastering Ethereum is the definitive no-fluff guide I recommend above all to achieve that.” —Gonçalo Magalhães, head of security, Immunefi “An extraordinary synthesis of foundational vision and modern practice, Mastering Ethereum stands as the definitive reference—a profound, complete, and remarkably clear guide to understanding and building secure, scalable decentralized applications on Ethereum.” — Brian Wu, blockchain architect and author “The second edition of Mastering Ethereum far surpasses the first by thoroughly covering some of the newest breakthroughs in blockchain technology such as proof of stake, decentralized finance, and zero-knowledge proofs.” —Caleb Lent, tech reviewer
(This page has no text content)
Andreas M. Antonopoulos, Gavin Wood, Carlo Parisi, Alessandro Mazza, and Niccolò Pozzolini Mastering Ethereum Implementing Smart Contracts SECOND EDITION
978-1-098-16842-1 [LSI] Mastering Ethereum by Andreas M. Antonopoulos, Gavin Wood, Carlo Parisi, Alessandro Mazza, and Niccolò Pozzolini Copyright © 2026 Carlo Parisi, Alessandro Mazza, and Niccolò Pozzolini. All rights reserved. Published by O’Reilly Media, Inc., 141 Stony Circle, Suite 195, Santa Rosa, CA 95401. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisition Editor: Michelle Smith Development Editor: Shira Evans Production Editor: Clare Laylock Copyeditor: Shannon Turlington Proofreader: Piper Content Partners Indexer: WordCo Indexing Services, Inc. Cover Designer: Karen Montgomery Cover Illustrator: Karen Montgomery Interior Designer: David Futato Interior Illustrator: Kate Dullea December 2018: First Edition October 2025: Second Edition Revision History for the Second Edition 2025-10-06: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781098168421 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Mastering Ethereum, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the authors and do not represent the publisher’s views. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. This book is not intended as financial advice. Please consult a qualified professional if you require financial advice. Mastering Ethereum is available under the Creative Commons Attribution- Noncommercial-No Deriva‐ tive Works 4.0 International License (CC BY-NC-ND 4.0). The authors maintain an online version at https://oreil.ly/mastering-ethereum-2e-CC.
Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv 1. What Is Ethereum?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Ethereum Compared to Bitcoin 1 Components of a Blockchain 2 The Birth of Ethereum 4 Ethereum’s Stages of Development 6 Ethereum: A General-Purpose Blockchain 8 Ethereum’s Components 9 Ethereum and Turing Completeness 10 Turing Completeness as a “Feature” 10 Implications of Turing Completeness 11 From General-Purpose Blockchains to DApps 12 Ethereum’s Development Culture 13 Why Learn Ethereum? 14 Conclusion 14 2. Ethereum Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Ether Currency Units 15 Choosing an Ethereum Wallet 16 Control and Responsibility 17 Getting Started with MetaMask 18 Creating a Wallet 20 Switching Networks 23 Getting Some Test Ether 23 Sending Ether from MetaMask 27 Exploring the Transaction History of an Address 28 Introducing the World Computer 31 v
Externally Owned Accounts and Contracts 31 A Simple Contract: A Test Ether Faucet 32 Compiling the Faucet Contract 35 Creating the Contract on the Blockchain 37 Interacting with the Contract 40 Viewing the Contract Address in a Block Explorer 40 Funding the Contract 41 Withdrawing from Our Contract 43 Conclusion 48 3. Ethereum Nodes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Ethereum Networks 51 Should I Run a Full Node? 52 Full Node Advantages and Disadvantages 53 Public Testnet Advantages and Disadvantages 54 Local Blockchain Simulation Advantages and Disadvantages 55 Running an Ethereum Node 55 Hardware Requirements for a Full Node 55 Software Requirements for Building and Running a Client 57 Preparation Phase 58 Geth-Prysm 58 Reth-Lighthouse 62 The First Synchronization of Ethereum-Based Blockchains 65 The JSON-RPC Interface 66 Remote Ethereum Clients 68 Mobile (Smartphone) Wallets 69 Browser Wallets 69 Hardware Wallets 70 Conclusion 70 4. Cryptography. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Keys and Addresses 71 PKC and Cryptocurrency 73 Private Keys 75 Public Keys 76 Elliptic Curve Cryptography Explained 77 Elliptic Curve Arithmetic Operations 80 Generating a Public Key 82 Elliptic Curve Libraries 84 Cryptographic Hash Functions 84 Ethereum’s Cryptographic Hash Function: Keccak-256 86 vi | Table of Contents
Which Hash Function Am I Using? 86 Ethereum Addresses 87 Ethereum Address Formats 88 Hex Encoding with Checksum in Capitalization (ERC-55) 88 Detecting an Error in an ERC-55 Encoded Address 90 Validators’ Cryptography 90 Introduction 90 Requirements 92 BLS Digital Signatures 93 How Does It Work? 94 In Summary 96 KZG Cryptography 98 Introduction 99 Polynomial Commitment Schemes 100 Using Merkle Trees 101 KZG Commitment 103 KZG Proof 106 KZG Properties 109 Multiproofs 109 In Summary 112 Conclusion 114 5. Wallets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Overview of Wallet Technologies 115 Nondeterministic (Random) Wallets 117 Deterministic (Seeded) Wallets 118 Hierarchical Deterministic Wallets (BIP-32/BIP-44) 118 Seeds and Mnemonic Codes (BIP-39) 119 Wallet Best Practices 120 Mnemonic Code Words (BIP-39) 121 Optional Passphrase in BIP-39 125 Working with Mnemonic Codes 126 Creating an HD Wallet from the Seed 127 HD Wallets (BIP-32) 127 Extended Public and Private Keys 128 Hardened Child Key Derivation 129 Index Numbers for Normal and Hardened Derivation 129 HD Wallet Key Identifier (Path) 130 Navigating the HD Wallet Tree Structure 130 Security 132 Improving on User Experience 133 Table of Contents | vii
Account Abstraction 134 Social Recovery 146 ENS 146 Conclusion 147 6. Transactions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 The Structure of a Transaction 149 Legacy Transactions 150 EIP-2930 Transactions 151 EIP-1559 Transactions 152 EIP-4844 Transactions 154 EIP-7702 Transactions 154 The Transaction Nonce 155 Keeping Track of Nonces 157 Gaps in Nonces, Duplicate Nonces, and Confirmation 161 Concurrency, Transaction Origination, and Nonces 162 Transaction Gas 163 EIP-1559: Base Fee and Priority Fee 164 How to Know the “Correct” Gas Price 164 Transaction Recipient 165 Transaction Value and Data 166 Transmitting Value to EOAs and Contracts 170 Transmitting a Data Payload to an EOA or Contract 171 Special Transaction: Contract Creation 172 Digital Signatures 175 The ECDSA 176 How Digital Signatures Work 176 ECDSA Math 177 Transaction Signing in Practice 179 Raw Transaction Creation and Signing 179 Deserializing the Transaction 181 Raw Transaction Creation with EIP-155 183 The Signature Prefix Value (v) and Public Key Recovery 184 Separating Signing and Transmission (Offline Signing) 185 Transaction Life Cycle 187 Creating and Signing the Transaction 187 Sending the Transaction to the Network 187 Building the Block 188 Finalizing the Transaction 188 An Alternative Life Cycle 189 MEV and Proposer and Builder Separation 189 viii | Table of Contents
Private Mempools 191 New Transaction Life Cycle 191 Multiple-Signature Transactions 192 Conclusion 193 7. Smart Contracts and Solidity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 What Is a Smart Contract? 195 Life Cycle of a Smart Contract 196 Introduction to Ethereum High-Level Languages 197 Building a Smart Contract with Solidity 199 Selecting a Version of Solidity 200 Downloading and Installing Solidity 200 Development Environment 201 Writing a Simple Solidity Program 201 Compiling with the Solidity Compiler (solc) 202 The Ethereum Contract ABI 202 Selecting a Solidity Compiler and Language Version 203 Programming with Solidity 205 Data Types 205 Variables: Definition and Scope 207 Predefined Global Variables and Functions 208 Contract Definition 211 Functions 212 Contract Constructor 214 Function Modifiers 215 Contract Inheritance 216 Multiple Inheritance 219 Error Handling 221 Events 223 Calling Other Contracts 227 Gas Considerations 232 Best Practices 232 Estimating Gas Cost 233 Conclusion 235 8. Smart Contracts and Vyper. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 Vulnerabilities and Vyper 237 Comparison to Solidity 237 Modifiers 238 Class Inheritance 239 Inline Assembly 240 Table of Contents | ix
Function Overloading 240 Variable Typecasting 240 Decorators 241 Function and Variable Ordering 242 Compilation 243 Protecting Against Overflow Errors at the Compiler Level 244 Reading and Writing Data 245 Conclusion 246 9. Smart Contract Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 Security Best Practices 247 Security Risks and Antipatterns 249 Reentrancy 249 DELEGATECALL 256 Entropy Illusion 262 Unchecked CALL Return Values 264 Race Conditions and Front-Running 267 Denial of Service 269 Floating Point and Precision 272 Price Manipulation 276 Improper Input Validation 279 Signature Replay Attack 281 Smart Contracts Misconfiguration 285 Contract Libraries 287 Additional Resources 287 Conclusion 288 10. Tokens. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 How Tokens Are Used 289 Tokens and Fungibility 291 Counterparty Risk 291 Tokens and Intrinsicality 292 Utility, Equity, or Cash Grab? 292 It’s a Duck! 293 Tokens on Ethereum 294 The ERC-20 Token Standard 295 Launching Our Own ERC-20 Token 299 Issues with ERC-20 Tokens 309 ERC-721: NFT Standard 315 ERC-1155: Multitoken Standard 316 Using Token Standards 318 x | Table of Contents
What Are Token Standards and What Is Their Purpose? 318 Should You Use These Standards? 318 Detecting Standards: EIP-165 319 Security by Maturity 320 Extensions to Token Interface Standards 321 Conclusion 322 11. Oracles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 Why Oracles Are Needed 323 Oracle Use Cases and Examples 324 Oracle Design Patterns 326 Immediate-Read 326 Publish-Subscribe 327 Request-Response 328 Data Authentication 329 Computation Oracles 331 Decentralized Oracles 332 Cross-Chain Messaging Protocols 333 Conclusion 335 12. Decentralized Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 What Is a DApp? 337 Backend (Smart Contract) 339 Data Storage 340 Frontend (Web User Interface) 343 A Basic DApp Example 343 Installation Requirements 344 Creating the DApp 344 Starting the Chain 345 Deploying Your Contract 345 Starting the Frontend 346 Interacting with Your Contract 347 Deploying to Vercel 354 Further Decentralizing the DApp 354 Decentralized Websites 355 Limitations 355 Deploying to IPFS 356 From App to DApp 357 Conclusion 357 Table of Contents | xi
13. Decentralized Finance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 DeFi Versus Traditional Finance 360 DeFi Primitives 361 Decentralized Exchanges 362 Lending Markets 364 Oracles 367 Stablecoins 368 Liquid Staking 369 Real-World Assets 370 Bridges and Omnichain Protocols 371 (De)centralized Finance 373 Risks and Challenges in DeFi 373 Conclusion 375 14. The Ethereum Virtual Machine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 What Is the EVM? 377 Comparison with Existing Technology 380 What Are Other Blockchains Doing? 380 The EVM Instruction Set (Bytecode Operations) 381 Ethereum State 384 Ethereum Stateless 385 Merkle-Patricia Trie 386 A Deep Dive into the Components of the EVM 391 Stack 391 Memory 392 Storage 393 Calldata 394 Let’s Put Everything Together with a Concrete Example 395 Compiling Solidity to EVM Bytecode 402 Contract Deployment Code 405 Disassembling the Bytecode 407 Turing Completeness and Gas 415 What Is Gas? 415 Gas Accounting During Execution 416 Block Gas Limit 419 Concrete Implementations 421 The Biggest EVM Upgrade: EVM Object Format 422 Jumpdest Analysis 422 Adding and Deprecating Features 425 Code and Data Separation 427 Stack Too Deep 427 xii | Table of Contents
EOF 430 The Future of the EVM 434 Conclusion 434 15. Consensus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 Principles of Consensus 436 Safety 436 Finality 436 Liveness 437 Block Trees and Forking 437 Consensus via Proof of Work 438 Consensus via Proof of Stake 439 PoS Terminology 441 Nodes and Validators 441 Blocks and Attestations 441 LMD-GHOST 442 Latest Message Driven 444 Greediest Heaviest Observed Subtree 445 Incentives 448 Casper FFG: The Finality Gadget 451 Epochs and Checkpoints 452 Justification and Finalization 453 Slashing 454 Fork Choice Rule 455 The Casper Commandments 455 Accountable Safety and Plausible Liveness 456 A Practical Example: The Life Cycle of a Checkpoint 457 First Round: Justification 459 Second Round: Finalization 460 Conflicting Justification 461 Gasper: A Real Example 464 Controversy and Competition 472 Timing Games 472 Centralization of Supermajority 474 Conclusion 478 16. Scaling Ethereum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481 The Problems of Ethereum’s Layer 1 482 The Scalability Trilemma 482 Gas Costs and Network Congestion 483 State Growth and Storage Issues 484 Table of Contents | xiii
Block Propagation and MEV 485 Solutions 486 Scaling the L1 486 Rollups 489 Other Types of Scaling Solutions 494 Validiums 494 Sidechains 495 Based Rollups 495 Booster Rollups 496 Native Rollups 496 Danksharding 497 Proto-Danksharding 499 Stateless Ethereum 502 Weak Statelessness 503 Verkle Trees 503 Strong Statelessness 506 Conclusion 507 17. Zero-Knowledge Proofs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509 History 509 Definition and Properties 510 How Ethereum Uses Zero-Knowledge Proofs 511 L2s Also Benefit from ZK 513 A Small Example 513 Let’s Prove It 514 Issues 516 Zero Knowledge 517 Prover Commitment 519 Adding Randomness to the Commitment 521 Conclusion? Or Not… 521 Fiat-Shamir Heuristic 522 Conclusion? 524 SNARK Versus STARK 524 Zk-EVM and zk-VM 526 Conclusion 528 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529 xiv | Table of Contents
Preface This book is a collaboration between me (Carlo Parisi, aka Blackie), Alessandro Mazza, and Niccolò Pozzolini. The first edition, which of course heavily influenced our work, was written between 2016 and 2019 by Andreas M. Antonopoulos and Dr. Gavin Wood. In November 2023, a series of very fortunate coincidences brought Andreas and me together in Glasgow. There, after a few beers and a few autographs, I asked him if he had any intention of writing a second edition of Mastering Ethereum. This was because, even though the first edition is a masterpiece, it hasn’t aged well; it was published in 2019, back when Ethereum was still using proof of work and had a very different roadmap. Andreas’s response was that he wasn’t planning to write a second edition, but our conversation ended up sparking the idea that led me to take on this project. Less than a day after our meeting in Glasgow, I was talking with O’Reilly about the possibility of writing a second edition. I immediately knew this would be a big and important task. While I was honored by the opportunity, I was also afraid I might not be able to do a good enough job. I’ve been a fan of Andreas’s work for years; he’s the reason I was able to understand Bitcoin as deeply as I did back in 2014–2015, so I knew I needed help. The first person who came to mind was Alessandro. He was involved in the project within the first few hours. As soon as the opportunity became real, I texted and asked if he wanted to join me. He instantly and happily said yes (without knowing any of the conditions or even whether it was a paid job). Niccolò was a bit harder to convince. It took a full month of rejections to get him on board. Luckily, I’m very stubborn and wasn’t willing to take no for an answer. After one month, he finally agreed. With that, our full team was ready, and the Mastering Ethereum: Second Edition project was officially launched. xv
I hope that every reader of this book gains at least a bit of knowledge from it. Mastering Ethereum was a book that taught me—and thousands of others—so much, and we worked hard to maintain that same level of quality. It took two years of research and writing to complete, and I’d be lying if I said it was easy. We’re also very proud to be an all-Italian team on this project. Hopefully, that brings some pride to the Italian crypto community as well. How to Use This Book The book is intended to serve both as a reference manual and as a cover-to-cover exploration of Ethereum. The first two chapters offer a gentle introduction, suitable for novice users, and the examples in those chapters can be completed by anyone with a bit of technical skill. Those two chapters will give you a good grasp of the basics and allow you to use the fundamental tools of Ethereum. Parts of Chapter 3 and beyond are intended for programmers and include many technical topics and programming examples, but they still should be understandable by anyone, for the most part. To serve as both a reference manual and a cover-to-cover narrative about Ethereum, the book inevitably contains some duplication. Some topics, such as gas, have to be introduced early enough for the rest of the topics to make sense but are also examined in depth in their own sections. Finally, the book’s index allows readers to find very specific topics and the relevant sections with ease, by keyword. Intended Audience This book is mostly intended for everyone. This book will teach you how smart contract blockchains work, how to use them, and how to develop smart contracts and decentralized applications with them. The first few chapters are also suitable as an in-depth introduction to Ethereum for beginners. Code Examples The examples are illustrated in Solidity, Vyper, and JavaScript, using the command line of a Unix-like operating system. All the code snippets can be replicated on most operating systems with a minimal installation of compilers, interpreters, and libraries for the corresponding languages. Where necessary, we provide basic installation instructions and step-by-step examples of the output of those instructions. All the code snippets use real values and calculations where possible, so you can build from example to example and see the same results in any code you write to calculate the same values. For example, the private keys and corresponding public keys and xvi | Preface
addresses are all real. The sample transactions, contracts, blocks, and blockchain references have all been introduced to the actual Ethereum blockchain and are part of the public ledger, so you can review them. Ethereum Addresses and Transactions in this Book The Ethereum addresses, transactions, keys, QR codes, and blockchain data used in this book are, for the most part, real. That means you can browse the blockchain, look at the transactions offered as examples, retrieve them with your own scripts or programs, and so forth. However, note that the private keys used to construct the addresses printed in this book have been “burned.” This means that if you send money to any of these addresses, the money will be either lost forever or (more likely) appropriated, since anyone who reads the book can take it using the private keys printed herein. Do not send money to any of the addresses in this book. Your money will be taken by another reader or lost forever. Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. This element signifies a tip or suggestion. Preface | xvii
This element signifies a general note. This element indicates a warning or caution. Using Code Examples In our commitment to collaboration, we worked with O’Reilly Media to make this book available under a Creative Commons license. If you have a technical question or a problem using the code examples, please send an email to support@oreilly.com. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Mastering Ethereum, 2nd ed., by Andreas M. Antonopoulos, Gavin Wood, Carlo Parisi, Alessandro Mazza, and Niccolò Pozzolini (O’Reilly). Copyright 2026 Carlo Parisi, Alessandro Mazza, and Niccolò Pozzolini, 978-1-098-16842-1.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. xviii | Preface