@@ -13,75 +13,66 @@ import "hardhat/console.sol";
13
13
* @author BuidlGuidl
14
14
*/
15
15
contract YourContract {
16
- // State Variables
17
- address public immutable owner;
18
- string public greeting = "Building Unstoppable Apps!!! " ;
19
- bool public premium = false ;
20
- uint256 public totalCounter = 0 ;
21
- mapping (address => uint ) public userGreetingCounter;
16
+ // State Variables
17
+ address public immutable owner;
18
+ string public greeting = "Building Unstoppable Apps!!! " ;
19
+ bool public premium = false ;
20
+ uint256 public totalCounter = 0 ;
21
+ mapping (address => uint ) public userGreetingCounter;
22
22
23
- // Events: a way to emit log statements from smart contract that can be listened to by external parties
24
- event GreetingChange (
25
- address indexed greetingSetter ,
26
- string newGreeting ,
27
- bool premium ,
28
- uint256 value
29
- );
23
+ // Events: a way to emit log statements from smart contract that can be listened to by external parties
24
+ event GreetingChange (address indexed greetingSetter , string newGreeting , bool premium , uint256 value );
30
25
31
- // Constructor: Called once on contract deployment
32
- // Check packages/hardhat/deploy/00_deploy_your_contract.ts
33
- constructor (address _owner ) {
34
- owner = _owner;
35
- }
26
+ // Constructor: Called once on contract deployment
27
+ // Check packages/hardhat/deploy/00_deploy_your_contract.ts
28
+ constructor (address _owner ) {
29
+ owner = _owner;
30
+ }
36
31
37
- // Modifier: used to define a set of rules that must be met before or after a function is executed
38
- // Check the withdraw() function
39
- modifier isOwner () {
40
- // msg.sender: predefined variable that represents address of the account that called the current function
41
- require (msg .sender == owner, "Not the Owner " );
42
- _;
43
- }
32
+ // Modifier: used to define a set of rules that must be met before or after a function is executed
33
+ // Check the withdraw() function
34
+ modifier isOwner () {
35
+ // msg.sender: predefined variable that represents address of the account that called the current function
36
+ require (msg .sender == owner, "Not the Owner " );
37
+ _;
38
+ }
44
39
45
- /**
46
- * Function that allows anyone to change the state variable "greeting" of the contract and increase the counters
47
- *
48
- * @param _newGreeting (string memory) - new greeting to save on the contract
49
- */
50
- function setGreeting (string memory _newGreeting ) public payable {
51
- // Print data to the hardhat chain console. Remove when deploying to a live network.
52
- console.log (
53
- "Setting new greeting '%s' from %s " ,
54
- _newGreeting,
55
- msg .sender
56
- );
40
+ /**
41
+ * Function that allows anyone to change the state variable "greeting" of the contract and increase the counters
42
+ *
43
+ * @param _newGreeting (string memory) - new greeting to save on the contract
44
+ */
45
+ function setGreeting (string memory _newGreeting ) public payable {
46
+ // Print data to the hardhat chain console. Remove when deploying to a live network.
47
+ console.log ("Setting new greeting '%s' from %s " , _newGreeting, msg .sender );
57
48
58
- // Change state variables
59
- greeting = _newGreeting;
60
- totalCounter += 1 ;
61
- userGreetingCounter[msg .sender ] += 1 ;
49
+ // Change state variables
50
+ greeting = _newGreeting;
51
+ totalCounter += 1 ;
52
+ userGreetingCounter[msg .sender ] += 1 ;
62
53
63
- // msg.value: built-in global variable that represents the amount of ether sent with the transaction
64
- if (msg .value > 0 ) {
65
- premium = true ;
66
- } else {
67
- premium = false ;
68
- }
54
+ // msg.value: built-in global variable that represents the amount of ether sent with the transaction
55
+ if (msg .value > 0 ) {
56
+ premium = true ;
57
+ } else {
58
+ premium = false ;
59
+ }
69
60
70
- // emit: keyword used to trigger an event
71
- emit GreetingChange (msg .sender , _newGreeting, msg .value > 0 , msg .value );
72
- }
61
+ // emit: keyword used to trigger an event
62
+ emit GreetingChange (msg .sender , _newGreeting, msg .value > 0 , msg .value );
63
+ }
73
64
74
- /**
75
- * Function that allows the owner to withdraw all the Ether in the contract
76
- * The function can only be called by the owner of the contract as defined by the isOwner modifier
77
- */
78
- function withdraw () public isOwner {
79
- (bool success , ) = owner.call { value: address (this ).balance }("" );
80
- require (success, "Failed to send Ether " );
81
- }
65
+ /**
66
+ * Function that allows the owner to withdraw all the Ether in the contract
67
+ * The function can only be called by the owner of the contract as defined by the isOwner modifier
68
+ */
69
+ function withdraw () public isOwner {
70
+ (bool success , ) = owner.call { value: address (this ).balance }("" );
71
+ require (success, "Failed to send Ether " );
72
+ }
82
73
83
- /**
84
- * Function that allows the contract to receive ETH
85
- */
86
- receive () external payable {}
74
+ /**
75
+ * Function that allows the contract to receive ETH
76
+ */
77
+ receive () external payable {}
87
78
}
0 commit comments