Ownable

import "@thirdweb-dev/contracts/extension/Ownable.sol";

The Ownable smart contract extension is usable with any base smart contract. It lets you set an owner for your smart contract.

GitHub
View on GitHub

Usage

The Ownable extension is an abstract contract, and expects you to implement the following functions by yourself:

NameTypeReturnsDescription
_canSetOwnerinternal view virtualboolRuns on every attempt to set the owner of the contract. Returns whether the owner can be set in the given execution context.

This is an example smart contract demonstrating how to inherit from this extension and override the functions to add (optional) custom functionality.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@thirdweb-dev/contracts/extension/Ownable.sol";
contract MyContract is Ownable {
/**
* This function returns who is authorized to set the owner of your contract.
*
* As an EXAMPLE, we'll only allow the current owner to set the contract's new owner.
*
* You MUST complete the body of this function to use the `Ownable` extension.
*/
function _canSetOwner() internal virtual view override returns (bool) {
return msg.sender == owner();
}
}

Base Contracts Implementing This Extension

All of the base contracts implement this extension.

Full API reference