Search code examples
polygonsoliditysmartcontractsremix

Smart contract ownership


I have renounced ownership of smart contract and now it is a null address (0x00..). Is there a way for me to reclaim ownership? As currently if I call transferOwnership - it comes back with error that caller is not owner.

Thanks in advance.


Solution

  • Is there a way for me to reclaim ownership?

    Simple answer: No.


    Unless... there's a function to specifically reclaim ownership from the zero address. Which would not make much sense to implement.

    // holds the previous owner before renouncing their ownership.
    address previousOwner;
    
    function reclaimOwnership() external {
        require(msg.sender == previousOwner);
        owner = msg.sender;
    }
    

    Assuming there's no such function:

    • Theoretically, you could reclaim the ownership by invoking the transferOwnership() function from the zero address, for which you'd need its private key. But it's practically impossible to guess its private key, and there's no record of anyone successfully guessing the zero address private key, ever.
    • Or if your contract was deployed using the CREATE2 opcode and has a selfdestroy mechanism, you could destroy and redeploy it to the same address, which would effectively set the owner value to the deployer (depending on your implementation, but most contracts set the owner in the constructor). But it's not very common to have this combination in a contract if you're not specifically counting on this option beforehand.