CCIP v1.6.2 Ownable2Step Contract API Reference
Ownable2Step
A minimal contract that implements 2-step ownership transfer and nothing more. It's made to be minimal to reduce the impact of the bytecode size on any contract that inherits from it.
note
This contract implements a secure two-step ownership transfer process:
- Current owner initiates transfer using transferOwnership
- New owner must accept using acceptOwnership
- Transfer only completes after both steps
This prevents accidental transfers to incorrect or inaccessible addresses.
Events
OwnershipTransferRequested
event OwnershipTransferRequested(address indexed from, address indexed to);
note
Emitted when the current owner initiates an ownership transfer.Parameters
| Name | Type | Description | 
|---|---|---|
| from | address | Current owner initiating the transfer | 
| to | address | Proposed new owner | 
OwnershipTransferred
event OwnershipTransferred(address indexed from, address indexed to);
note
Emitted when an ownership transfer is completed.Parameters
| Name | Type | Description | 
|---|---|---|
| from | address | Previous owner | 
| to | address | New owner | 
Errors
CannotTransferToSelf
error CannotTransferToSelf();
note
Thrown when attempting to transfer ownership to the current owner.MustBeProposedOwner
error MustBeProposedOwner();
note
Thrown when someone other than the pending owner tries to accept ownership.OnlyCallableByOwner
error OnlyCallableByOwner();
note
Thrown when a restricted function is called by someone other than the owner.OwnerCannotBeZero
error OwnerCannotBeZero();
note
Thrown when attempting to set the owner to address(0).State Variables
s_owner
The owner is the current owner of the contract.
address private s_owner;
note
The owner is the second storage variable so any implementing contract could pack other state with it instead of the much less used s_pendingOwner.
s_pendingOwner
The pending owner is the address to which ownership may be transferred.
address private s_pendingOwner;
Functions
acceptOwnership
Allows an ownership transfer to be completed by the recipient.
function acceptOwnership() external override;
note
Reverts with MustBeProposedOwner if caller is not the pending owner.
When successful:
- Updates owner to the caller
- Clears pending owner
- Emits OwnershipTransferred event
constructor
Initializes the contract with an owner and optionally a pending owner.
constructor(address newOwner, address pendingOwner);
note
- Reverts with OwnerCannotBeZeroif newOwner is address(0)
- Sets newOwner as the initial owner
- If pendingOwner is not address(0), initiates ownership transfer to pendingOwner
Parameters
| Name | Type | Description | 
|---|---|---|
| newOwner | address | The initial owner of the contract | 
| pendingOwner | address | Optional address to initiate ownership transfer to | 
onlyOwner
Modifier that restricts function access to the contract owner.
modifier onlyOwner();
note
Reverts withOnlyCallableByOwner if caller is not the current owner. owner
Returns the current owner's address.
function owner() public view override returns (address);
Returns
| Type | Description | 
|---|---|
| address | The address of the current owner | 
transferOwnership
Allows an owner to begin transferring ownership to a new address.
function transferOwnership(address to) public override onlyOwner;
note
The new owner must call acceptOwnership to complete the transfer. No permissions are changed until acceptance.
Reverts with:
- OnlyCallableByOwnerif caller is not the current owner
- CannotTransferToSelfif attempting to transfer to current owner
Parameters
| Name | Type | Description | 
|---|---|---|
| to | address | The address to which ownership will be transferred | 
_validateOwnership
Internal function to validate access control.
function _validateOwnership() internal view;
note
Reverts withOnlyCallableByOwner if caller is not the current owner. Used by the onlyOwner modifier.