Skip to main content
Try out the RareSkills ZK AI Tutor!
Learn Solidity: Free Solidity Course and Tutorial

OpenZeppelin Ownable: Use Ownable2Step Instead

Last updated on Nov 12, 2026

The onlyOwner modifier is probably one of the most common patterns in Solidity.

In the following example, the function setMessage() can only be called by the address designated to be the owner.

function setMessage(string calldata _message) external onlyOwner {
    message = _message;
}

However, the commonly used OpenZeppelin Ownable implementation has a shortcoming that it allows the owner to transfer ownership to a non-existent or mistyped address.

Ownable2Step is safer than Ownable for smart contracts because the owner cannot accidentally transfer smart contract ownership to a mistyped address. Rather than directly transferring to the new owner, the transfer only completes when the new owner accepts ownership.

Ownable2Step was released in January 2023 during the OpenZeppelin version 4.8 update. Here is the code.

Here is an minimal example:

import "@openzeppelin/contracts/access/Ownable2Step.sol";

contract ExampleOwnable2Step is Ownable2Step {
    string public message;

    constructor() Ownable(msg.sender) {}

    function setMessage(string calldata _message) external onlyOwner {
        message = _message;
    }
}

Ownable2Step inherits from Ownable and overrides transferOwnership() to make the new owner “pending.” The receiver must then call acceptOwnership() to finalize the transfer. This ensures only an address that has access to it’s private keys, or control of the smart contract address, can control the smart contract.

There is still no two-step verification for renouncing ownership, i.e. transferring ownership to the zero address. If there is no need to renounce ownership, then it is safer to override “renounceOwnership()” to revert when called.

Learn More

This tutorial is part of our advanced solidity bootcamp.

Originally Published Apr 8, 2023

Related posts

6 min read

Formally Verifying Ownable.sol

Ownable is an abstract contract that provides owner-based access control.

Last updated onNov 12, 2026
Read Article

12 min read

The initializable smart contract design pattern

Initializers are how upgradeable contracts achieve the behavior of a constructor.

Last updated onNov 12, 2026
Read Article

13 min read

Components Part 2: OpenZeppelin ERC-20 Tutorial

In Component Part 1, we learned how to create and use a component within a single file.

Last updated onDec 11, 2025
Read Article

6 min read

Tx.origin, msg.sender, and onlyOwner in Solana: identifying the caller

In Solidity, the msg.sender is a global variable that represents the address that called or initiated a function call on a smart contract.

Last updated onNov 12, 2026
Read Article