Skip to content

Instantly share code, notes, and snippets.

@codeWhizperer
Created August 10, 2023 09:50
Show Gist options
  • Select an option

  • Save codeWhizperer/5d95e6547f8e763f1680d3bc2b59de8e to your computer and use it in GitHub Desktop.

Select an option

Save codeWhizperer/5d95e6547f8e763f1680d3bc2b59de8e to your computer and use it in GitHub Desktop.
#[starknet::interface]
trait IHelloStarknet<TContractState> {
fn increase_balance(ref self: TContractState, amount: felt252);
fn get_balance(self: @TContractState) -> felt252;
}
#[starknet::contract]
mod HelloStarknet {
#[storage]
struct Storage {
balance: felt252,
}
#[external(v0)]
impl HelloStarknetImpl of super::IHelloStarknet<ContractState> {
fn increase_balance(ref self: ContractState, amount: felt252) {
assert(amount != 0, 'Amount cannot be 0');
self.balance.write(self.balance.read() + amount);
}
fn get_balance(self: @ContractState) -> felt252 {
self.balance.read()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment