Skip to main content

LSP14Ownable2Step

Solidity contract

The LSP14Ownable2Step contract is an implementation of the LSP14-Ownable-2-Step Standard.

This contract can be inherited whenever one wants to make his contract owned by an EOA or by another contract. This contract contains all the necessary methods for managing the ownership of a contract, tranferOwnership(...), acceptOwnership(...) and renounceOwnership(...).


Functions​

owner​

function owner() public view returns (address owner)

Returns the address of the current contract owner.

Return Values:​

NameTypeDescription
owneraddressThe current owner of the contract.

pendingOwner​

function pendingOwner() public view returns (address)

Return the address of the pending owner that was initiated by transferOwnership(address).

NB: if no ownership transfer is in progress, the pendingOwner MUST be address(0).

Return Values:​

NameTypeDescription
pendingOwneraddressThe address of the pending owner

transferOwnership​

function transferOwnership(address newOwner) public

Initiate an ownership transfer by setting the newOwner as pendingOwner.

Requirements:

  • Can only be called by the current owner.
  • The newOwner to be set as the pendingOwner cannot be address(this).

Parameters:​

NameTypeDescription
newOwneraddressThe address to set as pendingOwner.

acceptOwnership​

function acceptOwnership() public

Transfers ownership of the contract to the pendingOwner address. Can only be called by the pendingOwner.

Triggers the OwnershipTransferred event once the new owner has claimed ownership.

renounceOwnership​

function renounceOwnership() public

Since renouncing ownership is a sensitive operation, it is done as a two step process by calling renounceOwnership(..) twice. First to initiate the process, second as a confirmation.

The current block number is saved as a part of initiation because the following behaviour is wanted:

  • The first 100 blocks after the saved block is the pending period, if you call renounceOwnership(..) during this period, the transaction will be reverted.
  • the following 100 blocks is the period when you can confirm the renouncement of the contract by calling renounceOwnership(..) the second time.

Triggers the RenounceOwnershipStarted event in the first call.

Triggers the OwnershipTransferred and OwnershipRenounced events after successfully renouncing ownership.

danger

Leaves the contract without an owner. Once ownership of the contract is renounced, it won't be possible to call the functions restricted to the owner only.

Events​

OwnershipTransferStarted​

event OwnershipTransferred(
address indexed currentOwner,
address indexed newOwner,
)

MUST be fired when the transferOwnership(...) function is successfully initiated.

Values:​

NameTypeDescription
currentOwneraddressThe current owner of the contract.
newOwneraddressThe potential new owner of the contract.

OwnershipTransferred​

event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner,
)

MUST be fired when the transferOwnership(...) function is successfully executed.

Values:​

NameTypeDescription
previousOwneraddressThe previous owner of the contract.
newOwneraddressThe new owner of the contract.

RenounceOwnershipStarted​

event RenounceOwnershipStarted()

MUST be fired when the renounceOwnership() process is initiated.

OwnershipRenounced​

event OwnershipRenounced()

MUST be fired when the renounceOwnership() process is confirmed.

References​