ERC20Pausable.sol [Code Snippet]
Enables pausing of token transfers during emergencies.

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;


import "../ERC20.sol";


abstract contract ERC20Pausable is ERC20 {

  bool private _paused;


  event Paused(address account);

  event Unpaused(address account);


  modifier whenNotPaused() {

    require(!_paused, "ERC20Pausable: token transfer while paused");

    _;

  }


  modifier whenPaused() {

    require(_paused, "ERC20Pausable: not paused");

    _;

  }


  function pause() external whenNotPaused {

    _paused = true;

    emit Paused(msg.sender);

  }


  function unpause() external whenPaused {

    _paused = false;

    emit Unpaused(msg.sender);

  }


  // Override transfer functions to include `whenNotPaused` modifier.

}



Share by: