Skip to main content

Owner Transfer Facet

Manages diamond ownership and transfers

Key Features
  • Manages diamond ownership via external functions.
  • Leverages diamond storage for owner state.
  • Provides exportSelectors for facet discovery.
  • Compatible with ERC-2535 diamond standard.

Overview

This facet provides external functions for managing the ownership of a Compose diamond. It enables transferring ownership and renouncing it, interacting with diamond storage for owner information. Developers integrate this facet to establish clear ownership and control within their diamond architecture.

Storage

OwnerStorage

Definition
struct OwnerStorage {
address owner;
}

State Variables

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

Functions

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.

exportSelectors

Exports the function selectors of the OwnerTransferFacet This function is use as a selector discovery mechanism for diamonds

function exportSelectors() external pure returns (bytes memory);

Returns:

PropertyTypeDescription
-bytesselectors The exported function selectors of the OwnerTransferFacet

Events

Errors

Best Practices

Best Practice
  • Initialize the owner address during diamond deployment.
  • Enforce access control for state-changing functions like transferOwnership.
  • Verify compatibility with OwnerDataFacet and OwnerRenounceFacet when composing access control functionalities.

Security Considerations

Security

State-changing functions, particularly transferOwnership, must be protected by appropriate access control mechanisms (e.g., Ownable or role-based access control) to prevent unauthorized ownership changes. Ensure the caller has the necessary permissions before executing transferOwnership. Renouncing ownership by setting the new owner to address(0) is irreversible. Follow standard Solidity security practices for input validation and reentrancy.

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.