Chapter 5
Building an ERC-20 Token
ERC-20 is the standard for fungible tokens on Ethereum. Wallets, DEXs, and lending protocols all expect the same core methods — balanceOf, transfer, approve, and transferFrom — so building a compliant token unlocks instant ecosystem compatibility.
When implementing from scratch, inherit OpenZeppelin's ERC20 and override _update or _mint hooks rather than rewriting transfer math. Reentrancy through hooks is rare in ERC-20 but fee-on-transfer and rebasing tokens break the assumption that balance changes match the amount parameter — document deviations clearly.
Always emit Transfer and Approval events for every state change. Off-chain apps index these logs to show balances and permissions; missing events make your token invisible to block explorers and portfolio trackers even if on-chain state is correct.