Chapter 4
Libraries and Custom Errors
Libraries extract reusable logic — math helpers, signature verification, array utilities — into deployable units that multiple contracts can call. Custom errors replace long revert strings with compact selectors that save gas and improve readability in modern Solidity.
Internal library functions are inlined at compile time, while external ones require a linked library address. For most projects, internal libraries and OpenZeppelin's battle-tested utilities cover the common cases without extra deploy steps.
Prefer custom errors over require(false, "long message") in new code. The gas savings add up across every revert path, and error names document intent better than generic failure strings scattered through the codebase.