Skip to main content

OwnerFacet

Manages diamond contract ownership and transfers

Key Features
  • Provides external view function owner() to check contract ownership.
  • Supports ownership transfer via transferOwnership(address).
  • Allows ownership renouncement via renounceOwnership().
  • Utilizes diamond storage for owner state.

Overview

This facet implements ownership management for a diamond contract. It exposes functions to view the current owner, transfer ownership to a new address, and renounce ownership entirely. Developers integrate this facet to establish clear ownership and control over diamond upgradeability and configuration.


Storage

OwnerStorage

Definition
struct OwnerStorage {
address owner;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("compose.owner"))

Functions

owner

Get the address of the owner

function owner() external view returns (address);

Returns:

PropertyTypeDescription
-addressThe address of the owner.

transferOwnership

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

function transferOwnership(address _newOwner) external;

Parameters:

PropertyTypeDescription
_newOwneraddressThe address of the new owner of the contract

renounceOwnership

function renounceOwnership() external;

Events

Errors

Best Practices

Best Practice
  • Initialize the owner address during diamond deployment.
  • Enforce ownership checks on sensitive functions through the owner() view function.
  • Use transferOwnership for planned ownership changes and renounceOwnership with extreme caution.

Security Considerations

Security

The transferOwnership function allows setting the owner to address(0), effectively renouncing ownership. Ensure this action is intended before execution. All state-changing functions are implicitly protected by the owner role, as only the current owner can call transferOwnership and renounceOwnership through the diamond proxy.

Was this helpful?
Last updated: