Skip to main content

Owner Transfer Module

ERC-173 ownership transfer for diamond facets

Key Features
  • Helper functions for ownership transfer and storage access.
  • transferOwnership guards by requiring msg.sender is the stored owner.
  • Emits OwnershipTransferred on successful transfers.
Module Usage

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

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

getStorage

Returns a pointer to the ERC-173 OwnerStorage struct. Uses inline assembly to bind the slot to STORAGE_POSITION.

function getStorage() pure returns (OwnerStorage storage s);

Returns:

PropertyTypeDescription
sOwnerStorage storageThe 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).

function transferOwnership(address _newOwner);

Parameters:

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

Events

Errors

Best Practices

  • Call transferOwnership only from trusted external wrappers; confirm _newOwner before sending a transaction.
  • Keep the same STORAGE_POSITION and OwnerStorage layout as other owner modules; do not introduce a second owner slot.
  • If you want a dedicated renounce entrypoint in Solidity, prefer OwnerRenounceMod or pass address(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.

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.