Owner Transfer Facet
ERC-173 ownership transfer for Compose diamonds
transferOwnershipwrites into theOwnerStorageaterc8042:erc173.owner(shared with other owner facets)._newOwnermay beaddress(0)to clear ownership. (Similar torenounceOwnership)- Non-owners revert
OwnerUnauthorizedAccount; successful transfers emitOwnershipTransferred.
Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Owner storage position within the diamond (Value: keccak256("erc173.owner")) |
OwnerStorage
Functions
transferOwnership
Updates OwnerStorage.owner to _newOwner when msg.sender is the current owner; otherwise reverts OwnerUnauthorizedAccount. Emits OwnershipTransferred(previousOwner, _newOwner). Use _newOwner == address(0) to clear the owner (irreversible unless another facet or upgrade restores it).
Parameters:
| Property | Type | Description |
|---|---|---|
_newOwner | address | The next owner, or address(0) to clear ownership. |
Events
Errors
Best Practices
- Initialize
OwnerStorage.ownerduring deployment (or via a one-time setup) before relying on owner-only features elsewhere. - Confirm
_newOwneris the intended address; transfers are immediate and cannot be undone. - Keep owner state in a single slot: do not add another facet that writes a second “owner” elsewhere.
- If you need two-step acceptance or pending-owner flows, consider the Two Steps ownership utilities in addition to this facet.
Security Considerations
transferOwnership is restricted to the address currently stored as owner (msg.sender == s.owner). The facet does not implement any additional role system. View Access Control for granular role-based access.
The main risks are social and operational: transferring to the wrong address, or setting _newOwner to address(0) when you did not intend to remove all owner control.