Created
August 31, 2024 15:06
-
-
Save avirajkhare00/9b235cb0cd87a2d121292bae4230a044 to your computer and use it in GitHub Desktop.
Starknet contract assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[starknet::contract] | |
pub mod SimpleCounter { | |
#[storage] | |
struct Storage { | |
// Counter variable | |
counter: u128, | |
} | |
#[constructor] | |
fn constructor(ref self: ContractState, init_value: u128) { | |
// Store initial value | |
self.counter.write(init_value); | |
} | |
#[abi(embed_v0)] | |
impl SimpleCounter of super::ISimpleCounter<ContractState> { | |
fn get_current_count(self: @ContractState) -> u128 { | |
return self.counter.read(); | |
} | |
fn increment(ref self: ContractState) { | |
// Store counter value + 1 | |
let counter = self.counter.read() + 1; | |
self.counter.write(counter); | |
} | |
fn decrement(ref self: ContractState) { | |
// Store counter value - 1 | |
let counter = self.counter.read() - 1; | |
self.counter.write(counter); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment