What is Pausable.sol used for in a Smart Contract?

Hello! I am very new to Solidity and I'm wondering what Pausable.sol is used for. In the OpenZeppelin Docs, it says that there are modifiers whenNotPaused and whenPaused, to be used in functions when a smart contract is "paused" or "unpaused". My question is, what exactly are you pausing? Are you pausing one specific function (for example, one that's being used to make a transaction), or are you pausing all of the functions in a smart contract just so one function can work? I know the Docs say that this file can be used to pause a contract for emergencies, but can you just pause one specific thing that your contract is doing (for example, if someone wants to get some tokens, but has to wait a period of time before they can get their money)? Thank you for taking the time to read this, and I hope this can be cleared up soon. :grinning_face_with_smiling_eyes:

1 Like

Pausable.sol is awesome! You call it like this:

import './path/to/Pausable.sol';

contract Flora is Pausable {
}

Deploy anything with it in there and you'll have the public calls to "pause" and "unpause" on the whole contract.

Run something through remix on a testnet, verify it's source and look in the read/write contract.

To do it individually in a function, you use the modifier whenNotPaused:

    function mint(address recipient, uint256 _amount)
        public
        whenNotPaused
        onlyOperator
        MintWrappersOn(recipient)
    {
        // require(_minter_role_address[user] == false, "Blacklisted");
        _mint(recipient, _amount);
        _moveDelegates(address(0), _delegates[recipient], _amount);
    }

In this example, you can see how I stacked extra modifiers in there. Only the contracts defined "Operator" can call the function, and there's another modifier "MintWrappersOn" that takes a variable that it passes to the modifier to check stuff.

Defining the operator and roles comes later, to get started you would probably just want:

    function mint(address recipient, uint256 _amount)
        public
        whenNotPaused
        onlyOwner
    {
        // require(_minter_role_address[user] == false, "Blacklisted");
        _mint(recipient, _amount);
        _moveDelegates(address(0), _delegates[recipient], _amount);
    }

MIND THE ACCESS CONTROL OF onlyOwner! Google "parity multisig wallet hack" to learn why.

Hope this helps, and have a great day!

1 Like

Thanks so much, @Annabelle75! I'm sure I'll need to take a minute to digest everything, but your response is very helpful! Have a great day, and thanks again. :grinning_face_with_smiling_eyes::+1:t4:

1 Like