openzeppelin
Installation
SKILL.md
OpenZeppelin Contracts
OpenZeppelin Contracts is the standard library for secure smart contract development. Used by Uniswap, Aave, Compound, and most production Solidity projects. The library provides audited, modular building blocks for tokens, access control, security patterns, upgradeability, and governance.
What You Probably Got Wrong
OZ v5 shipped breaking changes in late 2023. Most LLM training data reflects v4. Every item below will cause compilation failures if you use the old pattern.
- Ownable requires a constructor argument --
Ownableno longer has a default owner. You MUST pass the initial owner address:Ownable(initialOwner). Omitting this is the #1 compilation error. - Import paths changed -- v5 uses
@openzeppelin/contracts/token/ERC20/ERC20.sol, not@openzeppelin/contracts/ERC20.sol. Some nested paths also changed. Always import from the full canonical path. _setupRoleis removed -- Use_grantRole(role, account)in the constructor instead._setupRoledoes not exist in v5._safeMintinternal visibility --_safeMintis still internal but the override pattern changed. Override_updateinstead of_beforeTokenTransfer/_afterTokenTransfer.- Hook functions renamed --
_beforeTokenTransferand_afterTokenTransferare gone. Override_update(from, to, value)for ERC-20 and_update(to, tokenId, auth)for ERC-721. - ERC-721 Enumerable override -- v5 requires overriding
_increaseBalancein addition to_updatewhen combining ERC721Enumerable with other extensions. SafeMathis removed -- Solidity 0.8+ has built-in overflow checks.SafeMathwas deleted from v5 entirely.Countersis removed -- Use plainuint256with++instead. TheCounterslibrary was removed for being unnecessary abstraction.AccessControl.renounceRolerequirescallerConfirmation-- In v5,renounceRole(role, callerConfirmation)takes a second parameter to prevent accidental renouncement.