Skip to main content

Owner Data Module

Manages ERC-173 contract ownership using diamond storage

Key Features
  • Provides internal functions for ERC-173 ownership management.
  • Utilizes diamond storage pattern for shared state.
  • No external dependencies, promoting composability.
  • Functions are internal and designed for use within custom facets.
Module Usage

This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.

Overview

This module provides internal functions for managing ERC-173 contract ownership. Facets can import this module to check and set the contract owner using shared diamond storage. Changes to ownership are immediately visible to all facets accessing the same storage slot.

Storage

OwnerStorage

storage-location: erc8042:erc173.owner

Definition
struct OwnerStorage {
address owner;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc173.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
sOwnerStorageThe OwnerStorage struct in storage.

owner

Get the address of the owner

function owner() view returns (address);

Returns:

PropertyTypeDescription
-addressThe address of the owner.

requireOwner

Reverts if the caller is not the owner.

function requireOwner() view;

setContractOwner

function setContractOwner(address _initialOwner) ;

Parameters:

PropertyTypeDescription
_initialOwneraddress-

Events

Errors

Best Practices

Best Practice
  • Ensure access control is enforced by the calling facet before invoking setContractOwner.
  • Verify that the OwnerStorage struct and its storage position are correctly configured within the diamond's storage layout.
  • Handle OwnerUnauthorizedAccount and OwnerAlreadyRenounced errors if applicable to your facet's logic.

Integration Notes

Shared Storage

This module manages ownership state within the diamond's shared storage. It uses the OwnerStorage struct, located at the STORAGE_POSITION slot, identified by keccak256("erc173.owner"). The owner address is stored here. Any facet that accesses this storage position will see the current owner address. Functions like owner() and requireOwner() directly read from this slot, ensuring consistent ownership information across the diamond.

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.