TransWikia.com

How to disable one owner-only contract function without disabling others?

Ethereum Asked by Chenguang on February 27, 2021

I have deployed a smart contract with several functions that only one address (called the ‘owner’) is allowed to call. The transaction will revert if any other address tries to call one of them.

Is there a way to make it impossible for the owner (or anyone else) to call some of these functions while maintaining the ability for the owner to call the other functions?

The contract has a transferOwnership(address _newOwner) function with which the owner can set a different address as owner.

One Answer

If the original contract does not have this functionality built in, the only way to do this is to transfer ownership of the original contract to a new contract that looks something like this:

contract LimitedOwner is Ownable
{
    OriginalContract public ownedTokenContract;
    
    // Explicitly allow these functions to be called
    function burn(uint256 _amount) onlyOwner
    {
        ownedTokenContract.burn(_amount);
    }
    function mint(address _address, uint256 _amount) onlyOwner
    {
        ownedTokenContract.mint(_address, _amount);
    }
    
    // All the original contract's owner-only functions that have not been
    // implemented in this LimitedOwner contract can never be called again.
}

LimitedOwner should not be able to call transferOwnership on the original contract, because then the disabled functions could be re-enabled by transferring ownership away from the LimitedOwner. Instead, the LimitedOwner contract should have its own transferOwnership function to keep the ability to transfer ownership and to further limit the owner's abilities in the future.

If your original contract had no transferOwnership (or similar) function, it would not have been possible.

Correct answer by Jesbus on February 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP