EIPs Explained

ERC-173 · Final · ERC · 2018-06-07

ERC-173: Contract Ownership Standard

A tiny standard interface (owner, transferOwnership, OwnershipTransferred) for contracts that have a single owner, so tools and other contracts can read and transfer ownership the same way everywhere.

What problem does it solve?

Many contracts have an admin who can withdraw funds, pause the contract or change settings. Before ERC-173, each project named this differently, so a wallet, registry or marketplace could not ask "who controls this contract?" or "transfer control to X" in a generic way.

ERC-173 standardizes the pattern most contracts were already using, so user interfaces, contract wallets and registries can manage ownership of any compliant contract.

How it works

A compliant contract implements one interface:

Member Purpose
owner() Returns the current owner address
transferOwnership(newOwner) Sets a new owner. Should be restricted to the current owner
event OwnershipTransferred(previousOwner, newOwner) Emitted on every change, and also when the contract is created

Rules from the spec:

  • Passing the zero address to transferOwnership renounces ownership. After that, nobody owns the contract.
  • owner() may be view or pure. transferOwnership may be public or external.
  • Contracts should also implement ERC-165. The ERC-173 interface ID is 0x7f5828d0.

The authors kept it to two functions on purpose, so existing contracts were already compatible and it stays cheap. More advanced ownership models (ENS-based or NFT-based) can be added alongside it.

Sample code

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IERC173 {
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    function owner() external view returns (address);
    function transferOwnership(address newOwner) external;
}

contract Owned is IERC173 {
    address public owner;

    constructor() {
        owner = msg.sender;
        emit OwnershipTransferred(address(0), msg.sender);
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "not owner");
        _;
    }

    function transferOwnership(address newOwner) external onlyOwner {
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner; // address(0) renounces ownership
    }

    function supportsInterface(bytes4 id) external pure returns (bool) {
        return id == 0x7f5828d0 || id == 0x01ffc9a7; // ERC-173, ERC-165
    }
}

Reading the owner from TypeScript (ethers v6):

const c = new Contract(addr, ["function owner() view returns (address)"], provider);
console.log(await c.owner());

Things to know

  • OpenZeppelin's widely used Ownable contract exposes the same owner(), transferOwnership() and OwnershipTransferred event. Note that it rejects address(0) in transferOwnership and uses a separate renounceOwnership() instead.
  • A typo in transferOwnership permanently hands the contract to the wrong address. Two-step patterns (propose, then accept) avoid this. See ERC-8023, currently a Draft.
  • If only reading the owner is needed, ERC-5313 defines just owner().
  • If the owner is an externally owned account, its private key is a single point of failure. Many teams use a multisig or timelock as the owner.
  • This ERC is Final.

#ownership #access-control #admin #standard

Details

Authors
Nick Mudge (@mudgen), Dan Finlay <[email protected]>
Status
Final
Type
Standards Track / ERC
Created
2018-06-07
Required by

Machine-readable: Markdown · JSON