Ownable2Step API Reference
Ownable2Step is a reusable ownership primitive that manages contract ownership through a two-step transfer process: propose → accept.
If you implement this contract, ownership is transferred by proposing a new owner and requiring that owner to explicitly accept the role.
Usage Boundary
You do not call this contract directly in most cases.
- Contracts inherit this implementation to manage ownership.
- Administrators call these functions to transfer ownership.
- You are responsible for completing the full transfer lifecycle (proposal and acceptance).
Contract
@chainlink/contracts/src/v0.8/shared/access/Ownable2Step.sol
Import
import {Ownable2Step} from "@chainlink/contracts/src/v0.8/shared/access/Ownable2Step.sol";
Inheritance
abstract contract Ownable2Step is IOwnable
State
Storage
address private s_owner;
address private s_pendingOwner;
Constructor
constructor(address newOwner, address pendingOwner)
Initializes ownership and optional pending owner.
Reverts if newOwner is the zero address.
- If a pending owner is provided at deployment, ownership can be accepted immediately by that address.
External API
owner (public, view)
function owner()
public
view
override
returns (address)
Returns the current owner of the contract.
transferOwnership (public)
function transferOwnership(address to)
public
override
Proposes a new owner.
- Only callable by the current owner.
- Sets the pending owner and replaces any existing pending ownership proposal (previous pending owners can no longer accept ownership).
- Reverts if the proposed owner is the zero address.
acceptOwnership (external)
function acceptOwnership()
external
override
Accepts ownership of the contract.
- Can only be called by the proposed owner.
- Transfers ownership and clears the pending owner.
Internal Functions
_transferOwnership
function _transferOwnership(address to)
internal
Sets the pending owner.
_validateOwnership
function _validateOwnership()
internal
view
- Reverts if the caller is not the current owner.
Events
event OwnershipTransferRequested(address indexed from, address indexed to);
event OwnershipTransferred(address indexed from, address indexed to);
For a cross-contract event index, see Events.
Errors
error OwnerCannotBeZero();
error MustBeProposedOwner();
error CannotTransferToSelf();
error OnlyCallableByOwner();
For a cross-contract error index, see Errors
Notes
- Ownership transfer follows a two-step process: propose → accept.
- Ownership transfer is not complete until the pending owner calls
acceptOwnership. - Ownership transfer is pull-based: the proposed owner must actively accept ownership.
- While a pending owner is set, the current owner retains full control.
- A new ownership proposal overwrites any existing pending owner.
- If the pending owner does not call
acceptOwnership, ownership remains with the current owner indefinitely.
Security model
- Ownership cannot be transferred without explicit acceptance by the proposed owner.
- Only the current owner can initiate ownership transfers.
- Prevents accidental or unauthorized ownership changes.