Skip to main content

Owner Transfer Facet

ERC-173 ownership transfer for Compose diamonds

Key Features
  • transferOwnership writes into the OwnerStorage at erc8042:erc173.owner (shared with other owner facets).
  • _newOwner may be address(0) to clear ownership. (Similar to renounceOwnership)
  • Non-owners revert OwnerUnauthorizedAccount; successful transfers emit OwnershipTransferred.

Storage

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Owner storage position within the diamond (Value: keccak256("erc173.owner"))

OwnerStorage

Definition
/** @custom:storage-location erc8042:erc173.owner */
struct OwnerStorage {
address owner;
}

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).

function transferOwnership(address _newOwner) external;

Parameters:

PropertyTypeDescription
_newOwneraddressThe next owner, or address(0) to clear ownership.

Events

Errors

Best Practices

  • Initialize OwnerStorage.owner during deployment (or via a one-time setup) before relying on owner-only features elsewhere.
  • Confirm _newOwner is 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.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.