Skip to main content

Owner Two Step Transfer Module

Two-step ERC-173 ownership transfer logic

Key Features
  • Two-step handoff: current owner calls transferOwnership; the nominated address calls acceptOwnership to finalize (unlike single-step OwnerTransferMod).
  • Uses erc8042:erc173.owner and erc8042:erc173.owner.pending; same layout as Owner Two Step Transfer Facet.
  • File-level getOwnerStorage, getPendingOwnerStorage, transferOwnership, and acceptOwnership; emits OwnershipTransferStarted then OwnershipTransferred when acceptance completes.
Module Usage

Import this module into facets or shared setup code. Its helpers are file-level (effectively internal to your compilation unit). Call them from your facet’s external entrypoints.

Storage follows the diamond slot layout in this file; any code using the same OWNER_STORAGE_POSITION or PENDING_OWNER_STORAGE_POSITION shares state.

See Facets & Modules for more information.

Storage

State Variables

PropertyTypeDescription
OWNER_STORAGE_POSITIONbytes32Owner storage position within the diamond (Value: keccak256("erc173.owner"))
PENDING_OWNER_STORAGE_POSITIONbytes32Pending owner storage position within the diamond (Value: keccak256("erc173.owner.pending"))

OwnerStorage

Definition
/** @custom:storage-location erc8042:erc173.owner */
struct OwnerStorage {
address owner;
}

PendingOwnerStorage

Definition
/** @custom:storage-location erc8042:erc173.owner.pending */
struct PendingOwnerStorage {
address pendingOwner;
}

Functions

getOwnerStorage

Returns a storage pointer to OwnerStorage at OWNER_STORAGE_POSITION using inline assembly.

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

Returns:

PropertyTypeDescription
sOwnerStorage storageThe owner struct in diamond storage.

getPendingOwnerStorage

Returns a storage pointer to PendingOwnerStorage at PENDING_OWNER_STORAGE_POSITION using inline assembly.

function getPendingOwnerStorage() pure returns (PendingOwnerStorage storage s);

Returns:

PropertyTypeDescription
sPendingOwnerStorage storageThe pending-owner struct in diamond storage.

transferOwnership

Requires msg.sender == owner; otherwise reverts OwnerUnauthorizedAccount. Sets pendingOwner to _newOwner and emits OwnershipTransferStarted(owner, _newOwner). Does not change owner until acceptOwnership.

function transferOwnership(address _newOwner);

Parameters:

PropertyTypeDescription
_newOwneraddressAddress that must call acceptOwnership to become owner.

acceptOwnership

Requires msg.sender == pendingOwner; otherwise reverts OwnerUnauthorizedAccount. Assigns owner to the pending address, clears pendingOwner, and emits OwnershipTransferred(previousOwner, newOwner).

function acceptOwnership();

Events

Errors

Best Practices

  • Expose transferOwnership and acceptOwnership only through vetted external facet entrypoints; confirm _newOwner before initiating.
  • Keep the same OwnerStorage / PendingOwnerStorage layout as Owner Two Step Transfer Facet and Owner Two Step Data Module
  • owner is shared with OwnerDataMod and single-step owner code at keccak256("erc173.owner").
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.