Solidity Programming Essentials - Second Editionを読み進めてみる

本書は2022年6月発売(英語)。Ethereumのスマートコントラクト開発について書籍としてまとめているものとしては最新だと思われるので、読みながらエッセンスをメモしていきたいと思います。
洋書なので、もし原著を読まれる場合はこのスクラップを副読記事として読み進めてもらえるとありがたいなと思います。
Solidity Programming Essentials: A guide to building smart contracts and tokens using the widely used Solidity language, 2nd Edition (English Edition)

各チャプターの概要

Chapter 1:ブロックチェーン、イーサリアム、スマートコントラクト入門

Chapter 2:EthereumとSolidityのインストール

Chapter 3:Solidityの紹介
- いわゆるSolidityの文法紹介。プログラミング言語の文法は習うより慣れろな感じもする。
- Solidity特有のデータロケーション概念はおさえておく。

Chapter4:グローバル変数と関数

addressのメンバーに関する説明があっさりしているが、公式ドキュメントにより詳しい説明があった。
code and codehash
You can query the deployed code for any smart contract. Use .code to get the EVM bytecode as a bytes memory, which might be empty. Use .codehash get the Keccak-256 hash of that code (as a bytes32). Note that addr.codehash is cheaper than using keccak256(addr.code).

Chapter 5: Expressions and Control Structures
Solidityの制御構造について。一般的なプログラミング言語とほぼ同じなので、メモするほどのものはないなー。記事化は飛ばしで。

Chapter 6: Writing Smart Contracts
ようやくSolidityらしいところへ。
- Writing a simple contract
- Creating contracts
- Creating contracts via the new and existing address
- Contract constructor
- Contract composition
- Inheritance
- Encapsulation
- Polymorphism
- Method overloading
- Abstract contracts
- Interfaces
- Advance interfaces
- Library

本書では言葉で細かく説明しているけれども、コードを見れば分かるような話ばかりだったので、ざっくり要約してコード例を多く載せておいた。こっちの方が、改めて確認したいときに役に立つ。

Chapter 7: Solidity Functions, Modifiers, and Fallbacks
view
やpure
は自然に前の方のChapterのコード例で出てきていたけど、ちゃんとした説明はこのChapterで行われている。こういうの、初学者が一番困る書き方よなー。

Chapter 8: Exceptions, Events, and Logging
ようやく半分以上進んだ。

Chapter9:Basics of Truffle and Unit Testing
Truffleのウォークスルー。

Chapter10: Debugging Contracts
Remixでデバッグする方法が紹介されている。が、TruffleでローカルネットワークにデプロイしたコントラクトをRemixでデバッグするのはやりづらく、VSCode上で機動的にデバッグできるようにしたいところ。

本書の流れを無視してRemix拡張からデバッグする方法を掲載した。

Chapter 11: Assembly Programming

Chapter12: Upgradable Smart Contracts

Chapter13: Writing Secure Contracts
セキュリティのトピックは盛りだくさんですな。
より広範に知りたい場合は https://swcregistry.io/ を確認すると良い。

Chapter 14: Writing Token Contracts
いよいよラスト1章〜

Chapter 15: Solidity Design Patterns
やっと全章読みきったー!