Solidity Custom Errors: Gas‑Efficient Reverts with Typed Data
Solidity custom errors (v0.8.4+) replace revert strings with a 4‑byte selector and typed arguments, cutting bytecode size and gas on failure.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Solidity custom errors (v0.8.4+) replace revert strings with a 4‑byte selector and typed arguments, cutting bytecode size and gas on failure.
Hardhat's console.log brings print-style debugging to Solidity. Here's how it intercepts calls on the Hardhat Network, a working example, and why you must strip it before deploying.
Custom errors replace revert strings with typed, named parameters — saving ~500–800 gas per revert. Declare them in a shared file, trigger with revert ErrorName(args), and frontends decode automatically via the ABI. Includes a worked token example, gas comparison table, and verification steps.
Learn how Solidity’s `unchecked` block lets you skip automatic overflow checks for gas savings, when it’s safe to use, and a practical token transfer example that shows the trade‑offs and how to audit the code.
Replace require strings with Solidity custom errors (0.8.4+): declaration, revert syntax, Foundry/ethers decoding, gas verification, and migration pitfalls.
Learn how Solidity custom errors (since 0.8.4) replace costly revert strings with cheap, typed data, saving gas while keeping error messages readable off‑chain.
Should your contract accept Ether through receive() or a named payable function? A decision guide with a comparison table, trade-offs, and a validatable implementation pattern.
Solidity libraries cut bytecode via delegatecall, but they run in the caller's storage context—creating silent corruption risks when layouts diverge. A worked example shows how a nonce library breaks when a mapping shifts slots, plus gas numbers to decide when libraries actually pay off.
Solidity 0.8.4+ custom errors replace string revert messages with typed errors, reducing gas costs and contract size. This article explains syntax, a worked example, gas comparisons, version limits, and common pitfalls.