Skip to main content

Owner Transfer Module

Manages ERC-173 ownership transfer and renouncement

Key Features
  • Manages ERC-173 ownership transfers and renouncements.
  • Operates on shared diamond storage, ensuring cross-facet visibility.
  • Provides internal functions for integration within custom facets.
  • Reverts with OwnerUnauthorizedAccount if ownership rules are violated.
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 core ERC-173 ownership transfer logic, enabling diamonds to manage ownership securely. Facets can use its internal functions to transfer ownership or renounce it, ensuring clear accountability within the diamond. Changes to ownership are immediately reflected across all facets sharing the same diamond storage.

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.

transferOwnership

Set the address of the new owner of the contract. Set _newOwner to address(0) to renounce any ownership.

function transferOwnership(address _newOwner) ;

Parameters:

PropertyTypeDescription
_newOwneraddressThe address of the new owner of the contract.

Events

Errors

Best Practices

Best Practice
  • Ensure ownership is transferred or renounced only by the current owner.
  • Call transferOwnership with address(0) to safely renounce ownership.
  • Use getStorage to inspect ownership state, ensuring consistency across facets.

Integration Notes

Shared Storage

This module utilizes diamond storage at the STORAGE_POSITION slot, identified by keccak256("erc173.owner"), to manage the OwnerStorage struct. The owner field within this struct represents the diamond's owner. All functions operate internally and directly on this shared storage, making ownership changes immediately visible to any facet that reads from the same storage slot.

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.