Owner Transfer Module
ERC-173 ownership transfer for diamond facets
- Helper functions for ownership transfer and storage access.
transferOwnershipguards by requiringmsg.senderis the stored owner.- Emits
OwnershipTransferredon successful transfers.
Import this module into facets or shared setup code. Its functions are internal (including Solidity file-level helpers). Use them through your facet’s external entrypoints.
Storage follows the diamond slot layout in this file; any code using the same STORAGE_POSITION or related positions reads and writes shared state.
See Facets & Modules for more information.
Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Owner storage position within the diamond (Value: keccak256("erc173.owner")) |
OwnerStorage
Functions
getStorage
Returns a pointer to the ERC-173 OwnerStorage struct. Uses inline assembly to bind the slot to STORAGE_POSITION.
Returns:
| Property | Type | Description |
|---|---|---|
s | OwnerStorage storage | The struct in storage. |
transferOwnership
Requires msg.sender == s.owner, then sets s.owner to _newOwner and emits OwnershipTransferred(previousOwner, _newOwner). Reverts OwnerUnauthorizedAccount otherwise. Per NatSpec, _newOwner may be address(0) to clear ownership (same storage effect as renounceOwnership() in OwnerRenounceMod).
Parameters:
| Property | Type | Description |
|---|---|---|
_newOwner | address | Next owner, or address(0) to clear ownership. |
Events
Errors
Best Practices
- Call
transferOwnershiponly from trustedexternalwrappers; confirm_newOwnerbefore sending a transaction. - Keep the same
STORAGE_POSITIONandOwnerStoragelayout as other owner modules; do not introduce a second owner slot. - If you want a dedicated renounce entrypoint in Solidity, prefer
OwnerRenounceModor passaddress(0)here—both target the same storage field.
Integration Notes
OwnerStorage lives at keccak256("erc173.owner") inside the diamond—the same slot as OwnerDataMod, OwnerTransferFacet, and related owner code. Transferring here updates what owner() reads on OwnerDataFacet.