Skip to main content

Owner Data Module

ERC-173 ownership storage and helpers for diamond facets

Key Features
  • Helper functions for owner storage, reads, and owner checks.
  • requireOwner() guards by requiring msg.sender is the stored owner; setContractOwner has no access checks (trusted initialization only).
  • Emits OwnershipTransferred from setContractOwner with previousOwner == address(0).
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
/** storage-location: erc8042:erc173.owner */
struct OwnerStorage {
address owner;
}

Functions

getStorage

Returns a pointer to the ERC-173 storage struct.

Uses inline assembly to access the storage slot defined by STORAGE_POSITION.

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

Returns:

PropertyTypeDescription
sOwnerStorage storageThe struct in storage.

owner

Get the address of the owner

function owner() view returns (address);

Returns:

PropertyTypeDescription
-addressThe stored owner, or address(0) if never set or cleared.

requireOwner

Reverts with OwnerUnauthorizedAccount unless msg.sender equals the current owner.

function requireOwner() view;

Reverts:

PropertyTypeDescription
OwnerUnauthorizedAccounterrorCaller is not the current owner.

setContractOwner

Writes the inital owner address to storage and emits OwnershipTransferred(address(0), _initialOwner).

There is no msg.sender or role check performed. Use only from trusted initialization code, or wrap with your own checks in a facet.

function setContractOwner(address _initialOwner);

Parameters:

PropertyTypeDescription
_initialOwneraddressThe address of the initial owner.

Events

Errors

Best Practices

  • Call setContractOwner only from trusted init paths (constructor, one-off setup). For transfers, use OwnerTransferMod.transferOwnership or an equivalent facet so events record the real previous owner.
  • Guard external entrypoints with requireOwner() or equivalent before state changes restricted to the owner.

Integration Notes

OwnerStorage is located at keccak256("erc173.owner") inside the diamond.

All Compose Owner contracts use that slot, so owner() and transfer logic observe the same address.

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.