1

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.

4
  • Where's the code of that smart contract? Oct 26, 2020 at 13:29
  • 1
    it's just a basic openzeppelin ERC20 & Ownable contract
    – Chenguang
    Oct 26, 2020 at 14:15
  • I don't think this question should be closed for 'needs details'. It's a very generalizable question; not necessarily specific to the OP's code.
    – Jesbus
    Oct 26, 2020 at 14:51
  • It is, because the following terms do not have any standard definition, so the reader technically needs to guess what each and every one of them means: disable a function, burn, burn function, mint, mint function, destroying the whole ownership and ownership. Regardless of that, a typical answer in this case would be with code, so the exact question in question should be properly specified. Lastly, since the user has mentioned OZ in a response comment, it should be emphasized that: 1. OZ is not a standard (at least not yet). 2. OZ versions keep changing (specifically Ownable). Oct 26, 2020 at 14:59

1 Answer 1

2

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.

2
  • 1
    Thank you for your answer that helped. So variable ownedTokenContract would be the address of the original token contract. I would specify all functions still needed in the new contract and possibly also limit the burn function. After deployment of the new contract, i can transfer ownership from the token contract to the new contract. Did i understand this correctly?
    – Chenguang
    Oct 26, 2020 at 15:09
  • @Chenguang Yes, that all sounds right. Please be careful though, it is kind of a dangerous procedure; if you mess it up you can easily destroy the ownership. I recommend testing everything on testnet and being very mindful of every action. Also, you should be aware that when calling functions through the LimitedOwner, msg.sender in the token contract functions will be the LimitedOwner. There's no way to avoid that.
    – Jesbus
    Oct 26, 2020 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.