-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16-Modifiers-Exercise.sol
38 lines (29 loc) · 914 Bytes
/
16-Modifiers-Exercise.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract PausableToken {
address public owner;
bool public paused;
mapping(address => uint) public balances;
constructor() {
owner = msg.sender;
paused = false;
balances[owner] = 1000;
}
modifier onlyOwner() {
// 1️⃣ Implement the modifier to allow only the owner to call the function
_;
}
// 2️⃣ Implement the modifier to check if the contract is not paused
function pause() public onlyOwner {
paused = true;
}
function unpause() public onlyOwner {
paused = false;
}
// 3️⃣ use the notPaused modifier in this function
function transfer(address to, uint amount) public {
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
balances[to] += amount;
}
}