-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContract.sol
More file actions
33 lines (26 loc) · 1.12 KB
/
Contract.sol
File metadata and controls
33 lines (26 loc) · 1.12 KB
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
// contractaddress: 0x9D36c869633fbdb23cfAc47953A508a9b5dD6712
// To increase the counter, transact with the function 'incrementCounter'
// or send a transaction to the contractaddress with the following data: '0x5b34b966'
// To call the current value of the counter call the function 'getCounter'
// Solidity version specifier
pragma solidity ^0.8.0;
// Contract declaration
contract CounterContract {
// Private state variable to store the counter value
uint256 private counter;
// Event declaration to log counter updates
event CounterUpdated(uint256 newCounterValue);
// Constructor: initializes the counter with an initial value of 0
constructor() {
counter = 0;
}
// Getter function to retrieve the current counter value (view function)
function getCounter() external view returns (uint256) {
return counter;
}
// Function to increment the counter and emit the CounterUpdated event
function incrementCounter() external {
counter++; // Increment the counter value by 1
emit CounterUpdated(counter); // Emit an event with the updated counter value
}
}