1

In MyContract, I am providing special rights to the manager. But after some time and for some reason, I want to invalidate the manager. The following is my approach:

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

contract MyContract{ address manager; constructor(){ manager = msg.sender; }

function invalidate() public {
    require(msg.sender == manager); // Only manager can invalidate itself
    manager = address(0);
}

}

Is the right way of doing this or does this have some loopholes?

Reference to 0 address behavior.

Anupam
  • 572
  • 3
  • 16

1 Answers1

1

This would work great!

The invalidate() function is public, meaning anyone can call it. If you want to restrict who can call that address, you should add some require statements.

For example, if you want only the manager to be able to invalidate themself, you would write:

    function invalidate() public {
        require(msg.sender == manager);
        manager = address(0);
    }
Shane Fontaine
  • 18,036
  • 20
  • 54
  • 82
  • Thanks, @shane. It was just for example purposes. But let me update this so that other people don't get confused. – Anupam Dec 21 '20 at 14:41