freecoding.school100% FREE · NO SIGNUP
Ledger LandISSUE #85 of 90

gas optimization · packing storage · short-circuit

BlockyVSDouble-Spend Dan
Blocky saysGas optimization saves real money — pack storage, short-circuit, and minimize writes.

Since storage writes dominate gas, optimization means: pack multiple small variables into one storage slot, cache storage reads in memory, short-circuit conditions, use calldata for external params, prefer events over storage for data you only read off-chain, and batch operations. On a busy chain these techniques cut user fees substantially — gas efficiency is a core contract-design skill.

Power-ups you unlock

Double-Spend Dan attacks — common mistakes

Boss battleName three concrete ways to cut gas in a Solidity contract.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>pack: uint128 a; uint128 b; → one slot
cache: uint x = storageVar; use x in loop
emit Event() instead of storing read-only data</pre></body></html>
▶ Open the interactive comic issue
‹ Block Explorers · Reading The ChainSecurity · Reentrancy · Overflow · Access Control ›